/// <summary> /// Shows a popup at the current mouse position. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The view context.</param> /// <param name="settings">The optional popup settings.</param> public virtual void ShowPopup(object rootModel, string context = null, IDictionary <string, object> settings = null) { var popup = CreatePopup(rootModel, settings); var view = _viewModelLocator.LocateForModel(rootModel, context); popup.Child = view; ViewHelper.SetIsGenerated(popup, true); _viewModelBinder.Bind(rootModel, popup, context); var activatable = rootModel as IActivate; if (activatable != null) { activatable.Activate(); } var deactivator = rootModel as IDeactivate; if (deactivator != null) { popup.Closed += (s, e) => deactivator.Deactivate(true); } popup.IsOpen = true; popup.CaptureMouse(); }
/// <summary> /// Ensures the view is a page or provides one. /// </summary> /// <param name="model">The model.</param> /// <param name="view">The view.</param> /// <returns>The page.</returns> protected virtual Page EnsurePage(object model, object view) { var page = view as Page; if (page == null) { page = new Page { Content = view }; ViewHelper.SetIsGenerated(page, true); } return(page); }
/// <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); }