/// <summary> /// Makes sure the view is a window is is wrapped by one. /// </summary> /// <param name="model">The view model.</param> /// <param name="view">The view.</param> /// <param name="isDialog">Whethor or not the window is being shown as a dialog.</param> /// <returns>The window.</returns> protected virtual Window EnsureWindow(object model, object view, bool isDialog) { if (view is Window window) { var owner = this.InferOwnerOf(window); if (owner != null && isDialog) { window.Owner = owner; } } else { window = new MaterialDesignWindow { Content = view, SizeToContent = SizeToContent.WidthAndHeight }; window.SetValue(View.IsGeneratedProperty, true); var owner = this.InferOwnerOf(window); if (owner != null) { window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.Owner = owner; } else { window.WindowStartupLocation = WindowStartupLocation.CenterScreen; } } return(window); }
protected override Window EnsureWindow(object model, object view, bool isDialog) { if (view == null) { // TODO: handle } if (!(view is Window window)) { window = new MaterialDesignWindow { Content = view, SizeToContent = SizeToContent.WidthAndHeight }; window.SetValue(View.IsGeneratedProperty, true); // set this only if we created it here } var owner = this.InferOwnerOf(window); if (owner != null) { window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.Owner = owner; } else { window.WindowStartupLocation = WindowStartupLocation.CenterScreen; } if (isDialog) { window.ShowInTaskbar = window.Owner != null; window.SizeToContent = SizeToContent.WidthAndHeight; window.ResizeMode = ResizeMode.NoResize; } return(window); }