示例#1
0
        /// <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)
        {
            var window = view as Window;

            if (window == null)
            {
                window = new Window
                {
                    Content       = view,
                    SizeToContent = SizeToContent.WidthAndHeight
                };

                ViewHelper.SetIsGenerated(window, true);

                var owner = InferOwnerOf(window);
                if (owner != null)
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.Owner = owner;
                }
                else
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                var owner = InferOwnerOf(window);
                if (owner != null && isDialog)
                {
                    window.Owner = owner;
                }
            }

            return(window);
        }
示例#2
0
 /// <summary>
 /// Tries to close the specified view.
 /// </summary>
 /// <param name="view">The view to close.</param>
 /// <param name="dialogResult">The dialog result.</param>
 /// <returns>true, when close could be initiated; otherwise false.</returns>
 public bool TryClose(object view, bool?dialogResult)
 {
     return(ViewHelper.TryClose(view, dialogResult));
 }