public RibbonDataWindow(DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline, bool focusFirstControl = true) : base(mode, additionalButtons, defaultButton, setOwnerAndFocus, infoBarMessageControlGenerationMode, focusFirstControl) { }
public RibbonDataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline, bool focusFirstControl = true) : base(viewModel, mode, additionalButtons, defaultButton, setOwnerAndFocus, infoBarMessageControlGenerationMode, focusFirstControl) { SizeChanged += OnSizeChanged; Loaded += OnLoaded; // WindowChromeBehavior initialization has to occur in constructor. Otherwise the load event is fired early and performance of the window is degraded. InitializeWindowChromeBehavior(); this.SizeToContent = SizeToContent.Manual; this.ResizeMode = ResizeMode.CanResizeWithGrip; }
/// <summary> /// Initializes a new instance of this class with custom commands. /// </summary> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> public MetroDataWindow(DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline) : this(null, mode, additionalButtons, defaultButton, setOwnerAndFocus, infoBarMessageControlGenerationMode) { }
/// <summary> /// Initializes a new instance of the <see cref="DataWindow"/> class. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> public MetroDataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline) { if (CatelEnvironment.IsInDesignMode) { return; } Mode = mode; DefaultButton = defaultButton; _infoBarMessageControlGenerationMode = infoBarMessageControlGenerationMode; this.FixBlurriness(); SizeToContent = SizeToContent.WidthAndHeight; ShowInTaskbar = false; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; BorderThickness = new Thickness(1d); BorderBrush = Orchestra.ThemeHelper.GetAccentColorBrush(); this.ApplyIconFromApplication(); ThemeHelper.EnsureCatelMvvmThemeIsLoaded(); _logic = new WindowLogic(this, null, viewModel); _logic.TargetViewPropertyChanged += (sender, e) => { // Do not call this for ActualWidth and ActualHeight WPF, will cause problems with NET 40 // on systems where NET45 is *not* installed if (!string.Equals(e.PropertyName, "ActualWidth", StringComparison.InvariantCulture) && !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture)) { PropertyChanged.SafeInvoke(this, e); } }; _logic.ViewModelClosedAsync += OnViewModelClosedAsync; _logic.ViewModelChanged += (sender, e) => RaiseViewModelChanged(); _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(sender, e); ViewModelPropertyChanged.SafeInvoke(this, e); }; Loaded += (sender, e) => { _viewLoaded.SafeInvoke(this); OnLoaded(e); }; Unloaded += (sender, e) => { _viewUnloaded.SafeInvoke(this); OnUnloaded(e); }; SetBinding(TitleProperty, new Binding("Title")); if (additionalButtons != null) { foreach (var button in additionalButtons) { _buttons.Add(button); } } CanClose = true; CanCloseUsingEscape = true; Loaded += (sender, e) => Initialize(); Closing += OnDataWindowClosing; DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue)); if (setOwnerAndFocus) { this.SetOwnerWindowAndFocus(); } else { this.FocusFirstControl(); } }
/// <summary> /// Initializes a new instance of the <see cref="DataWindow"/> class. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> /// <param name="focusFirstControl">if set to <c>true</c>, the first control will get the focus.</param> public DataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline, bool focusFirstControl = true) { if (CatelEnvironment.IsInDesignMode) { return; } // Set window style (WPF doesn't allow styling on root elements of XAML files, too bad) // For more info, see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3059c0e4-c372-4da2-b384-28f271feef05/ SetResourceReference(StyleProperty, typeof(DataWindow)); Mode = mode; DefaultButton = defaultButton; _infoBarMessageControlGenerationMode = infoBarMessageControlGenerationMode; this.FixBlurriness(); SizeToContent = SizeToContent.WidthAndHeight; ShowInTaskbar = false; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; this.ApplyIconFromApplication(); ThemeHelper.EnsureCatelMvvmThemeIsLoaded(); _logic = new WindowLogic(this, null, viewModel); _logic.TargetViewPropertyChanged += (sender, e) => { // Do not call this for ActualWidth and ActualHeight WPF, will cause problems with NET 40 // on systems where NET45 is *not* installed if (!string.Equals(e.PropertyName, nameof(ActualWidth), StringComparison.InvariantCulture) && !string.Equals(e.PropertyName, nameof(ActualHeight), StringComparison.InvariantCulture)) { PropertyChanged?.Invoke(this, e); } }; _logic.ViewModelClosedAsync += OnViewModelClosedAsync; _logic.ViewModelChanged += (sender, e) => RaiseViewModelChanged(); _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(sender, e); ViewModelPropertyChanged?.Invoke(this, e); }; Loaded += (sender, e) => { _viewLoaded?.Invoke(this, EventArgs.Empty); OnLoaded(e); }; Unloaded += (sender, e) => { _viewUnloaded?.Invoke(this, EventArgs.Empty); OnUnloaded(e); }; SetBinding(TitleProperty, new Binding("Title")); if (additionalButtons != null) { foreach (var button in additionalButtons) { _buttons.Add(button); } } CanClose = true; CanCloseUsingEscape = true; Loaded += (sender, e) => Initialize(); DataContextChanged += (sender, e) => _viewDataContextChanged?.Invoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue)); // #1150 Subscribe in dispatcher to allow derived types to be the first handler Dispatcher.BeginInvoke(() => { Closing += OnDataWindowClosing; }); _focusFirstControl = focusFirstControl; if (setOwnerAndFocus) { this.SetOwnerWindowAndFocus(focusFirstControl: focusFirstControl); } else if (focusFirstControl) { this.FocusFirstControl(); } }
/// <summary> /// Initializes a new instance of the <see cref="DataWindow"/> class. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> public DataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable<DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline) { if (CatelEnvironment.IsInDesignMode) { return; } // Set window style (WPF doesn't allow styling on root elements of XAML files, too bad) // For more info, see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3059c0e4-c372-4da2-b384-28f271feef05/ #if SILVERLIGHT Style dataWindowStyle = null; if (this.TryFindResource(typeof(DataWindow), out dataWindowStyle)) { DefaultStyleKey = typeof (DataWindow); //Style = dataWindowStyle; } #else SetResourceReference(StyleProperty, typeof(DataWindow)); #endif Mode = mode; DefaultButton = defaultButton; _infoBarMessageControlGenerationMode = infoBarMessageControlGenerationMode; this.FixBlurriness(); #if NET SizeToContent = SizeToContent.WidthAndHeight; ShowInTaskbar = false; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; this.ApplyIconFromApplication(); #endif ThemeHelper.EnsureCatelMvvmThemeIsLoaded(); _logic = new WindowLogic(this, null, viewModel); _logic.TargetViewPropertyChanged += (sender, e) => { #if !NET // WPF already calls this method automatically OnPropertyChanged(e); PropertyChanged.SafeInvoke(this, e); #else // Do not call this for ActualWidth and ActualHeight WPF, will cause problems with NET 40 // on systems where NET45 is *not* installed if (!string.Equals(e.PropertyName, "ActualWidth", StringComparison.InvariantCulture) && !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture)) { PropertyChanged.SafeInvoke(this, e); } #endif }; _logic.ViewModelClosed += OnViewModelClosed; _logic.ViewModelClosedAsync += OnViewModelClosedAsync; _logic.ViewModelChanged += (sender, e) => RaiseViewModelChanged(); _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(sender, e); ViewModelPropertyChanged.SafeInvoke(this, e); }; Loaded += (sender, e) => { _viewLoaded.SafeInvoke(this); OnLoaded(e); }; Unloaded += (sender, e) => { _viewUnloaded.SafeInvoke(this); OnUnloaded(e); }; SetBinding(TitleProperty, new Binding("Title")); if (additionalButtons != null) { foreach (var button in additionalButtons) { _buttons.Add(button); } } CanClose = true; CanCloseUsingEscape = true; Loaded += (sender, e) => Initialize(); Closing += OnDataWindowClosing; DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue)); #if NET if (setOwnerAndFocus) { this.SetOwnerWindowAndFocus(); } else { this.FocusFirstControl(); } #endif }
/// <summary> /// Initializes a new instance of this class with custom commands. /// </summary> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> public DataWindow(DataWindowMode mode, IEnumerable<DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline) : this(null, mode, additionalButtons, defaultButton, setOwnerAndFocus, infoBarMessageControlGenerationMode) { }
/// <summary> /// Initializes a new instance of the <see cref="DataWindow"/> class. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> public DataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable<DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline) { // Set window style (WPF doesn't allow styling on root elements of XAML files, too bad) // For more info, see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3059c0e4-c372-4da2-b384-28f271feef05/ #if SILVERLIGHT Style dataWindowStyle = null; if (this.TryFindResource(typeof(DataWindow), out dataWindowStyle)) { DefaultStyleKey = typeof (DataWindow); //Style = dataWindowStyle; } #else SetResourceReference(StyleProperty, typeof(DataWindow)); #endif Mode = mode; DefaultButton = defaultButton; _infoBarMessageControlGenerationMode = infoBarMessageControlGenerationMode; if (Catel.Environment.IsInDesignMode) { return; } #if NET SizeToContent = SizeToContent.WidthAndHeight; ShowInTaskbar = false; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; SnapsToDevicePixels = true; #endif var viewModelType = (viewModel != null) ? viewModel.GetType() : GetViewModelType(); if (viewModelType == null) { Log.Debug("GetViewModelType() returned null, using the ViewModelLocator to resolve the view model"); viewModelType = _viewModelLocator.ResolveViewModel(GetType()); if (viewModelType == null) { const string error = "The view model of the view could not be resolved. Use either the GetViewModelType() method or IViewModelLocator"; Log.Error(error); throw new NotSupportedException(error); } } _logic = new WindowLogic(this, viewModelType, viewModel); _logic.TargetControlPropertyChanged += (sender, e) => { #if !NET // WPF already calls this method automatically OnPropertyChanged(e.FxEventArgs); PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs(e.PropertyName)); #else // Do not call this for ActualWidth and ActualHeight WPF, will cause problems with NET 40 // on systems where NET45 is *not* installed if (!string.Equals(e.PropertyName, "ActualWidth", StringComparison.InvariantCulture) && !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture)) { PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs(e.PropertyName)); } #endif }; _logic.ViewModelChanged += (sender, e) => { OnViewModelChanged(); ViewModelChanged.SafeInvoke(this, e); PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs("ViewModel")); }; _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(sender, e); ViewModelPropertyChanged.SafeInvoke(this, e); }; _logic.DetermineViewModelInstance += (sender, e) => { e.ViewModel = GetViewModelInstance(e.DataContext); }; _logic.DetermineViewModelType += (sender, e) => { e.ViewModelType = GetViewModelType(e.DataContext); }; _logic.ViewModelClosed += OnViewModelClosed; SetBinding(TitleProperty, new Binding("Title")); if (additionalButtons != null) { foreach (var button in additionalButtons) { _buttons.Add(button); } } CanClose = true; CanCloseUsingEscape = true; Loaded += (sender, e) => Initialize(); Closing += OnDataWindowClosing; Loaded += (sender, e) => OnLoaded(e); Unloaded += (sender, e) => OnUnloaded(e); #if NET if (setOwnerAndFocus) { this.SetOwnerWindowAndFocus(); } else { this.FocusFirstControl(); } #endif }
/// <summary> /// Initializes a new instance of the <see cref="DataWindow"/> class. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="mode"><see cref="DataWindowMode"/>.</param> /// <param name="additionalButtons">The additional buttons.</param> /// <param name="defaultButton">The default button.</param> /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param> /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param> public MetroDataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable<DataWindowButton> additionalButtons = null, DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true, InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline) { if (CatelEnvironment.IsInDesignMode) { return; } Mode = mode; DefaultButton = defaultButton; _infoBarMessageControlGenerationMode = infoBarMessageControlGenerationMode; this.FixBlurriness(); SizeToContent = SizeToContent.WidthAndHeight; ShowInTaskbar = false; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.CenterOwner; BorderThickness = new Thickness(1d); BorderBrush = Orchestra.ThemeHelper.GetAccentColorBrush(); this.ApplyIconFromApplication(); ThemeHelper.EnsureCatelMvvmThemeIsLoaded(); _logic = new WindowLogic(this, null, viewModel); _logic.TargetViewPropertyChanged += (sender, e) => { // Do not call this for ActualWidth and ActualHeight WPF, will cause problems with NET 40 // on systems where NET45 is *not* installed if (!string.Equals(e.PropertyName, "ActualWidth", StringComparison.InvariantCulture) && !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture)) { PropertyChanged.SafeInvoke(this, e); } }; _logic.ViewModelClosedAsync += OnViewModelClosedAsync; _logic.ViewModelChanged += (sender, e) => RaiseViewModelChanged(); _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(sender, e); ViewModelPropertyChanged.SafeInvoke(this, e); }; Loaded += (sender, e) => { _viewLoaded.SafeInvoke(this); OnLoaded(e); }; Unloaded += (sender, e) => { _viewUnloaded.SafeInvoke(this); OnUnloaded(e); }; SetBinding(TitleProperty, new Binding("Title")); if (additionalButtons != null) { foreach (var button in additionalButtons) { _buttons.Add(button); } } CanClose = true; CanCloseUsingEscape = true; Loaded += (sender, e) => Initialize(); Closing += OnDataWindowClosing; DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue)); if (setOwnerAndFocus) { this.SetOwnerWindowAndFocus(); } else { this.FocusFirstControl(); } }