/// <summary> /// Makes sure the view is a Form or is wrapped by one. /// </summary> /// <param name="model">The view model.</param> /// <param name="view">The view.</param> /// <param name="isDialog">if set to <c>true</c>, the Form is being shown as a dialog.</param> /// <returns>The original Form or a new Form embedding the "view" control.</returns> protected virtual Page EnsurePage(object model, object view, bool isDialog) { var page = view as Page; if (page == null) { page = new Page(); var contentControl = new ContentContainer() { Dock = DockStyle.Fill, Location = new Point(0, 0), TabIndex = 0, Content = model // when setting the Content property, the setter will locate and load the view }; //window.SetValue(View.IsGeneratedProperty, true); page.Controls.Add(contentControl); } return(page); }
/// <summary> /// Makes sure the view is a Form or is wrapped by one. /// </summary> /// <param name="model">The view model.</param> /// <param name="view">The view.</param> /// <param name="isDialog">if set to <c>true</c>, the Form is being shown as a dialog.</param> /// <returns>The original Form or a new Form embedding the "view" control.</returns> protected virtual Window EnsureWindow(object model, object view, bool isDialog) { var window = view as Window; if (window == null) { window = new Window(); var contentControl = new ContentContainer() { Dock = DockStyle.Fill, Location = new Point(0, 0), TabIndex = 0, Content = model // when setting the Content property, the setter will locate and load the view }; //window.SetValue(View.IsGeneratedProperty, true); window.Controls.Add(contentControl); #if WEBGUI var owner = ApplicationContext.WebGUIActiveForm; #else var owner = Window.ActiveForm; #endif if (null != owner && window != owner) { window.StartPosition = FormStartPosition.CenterParent; window.Owner = owner; } else { window.StartPosition = FormStartPosition.CenterScreen; } } else { var owner = InferOwnerOf(window); if (owner != null && isDialog) { window.Owner = owner; } else if (owner == null) { window.StartPosition = FormStartPosition.CenterScreen; } } return window; }