/// <summary> /// Creates a window. /// </summary> /// <param name="rootModel">The view model.</param> /// <param name="isDialog">Whethor or not the window is being shown as a dialog.</param> /// <param name="context">The view context.</param> /// <param name="settings">The optional popup settings.</param> /// <returns>The window.</returns> protected virtual async Task <Window> CreateWindowAsync(object rootModel, bool isDialog, object context, IDictionary <string, object> settings) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (string.IsNullOrEmpty(view.Title) && haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(Window.TitleProperty, binding); } ApplySettings(view, settings); var conductor = new WindowConductor(rootModel, view); await conductor.InitialiseAsync(); return(view); }
/// <summary> /// Creates the page. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The context.</param> /// <param name="settings">The optional popup settings.</param> /// <returns>The page.</returns> public virtual async Task <Page> CreatePageAsync(object rootModel, object context, IDictionary <string, object> settings) { var view = EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, context)); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (string.IsNullOrEmpty(view.Title) && haveDisplayName != null && !ConventionManager.HasBinding(view, Page.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(Page.TitleProperty, binding); } ApplySettings(view, settings); if (rootModel is IActivate activator) { await activator.ActivateAsync(); } if (rootModel is IDeactivate deactivatable) { view.Unloaded += async(s, e) => await deactivatable.DeactivateAsync(true); } return(view); }
///<summary> /// Checks if the <see cref="ActionMessage" /> -Target was set. ///</summary> ///<param name="element"> DependencyObject to check </param> ///<returns> True if Target or TargetWithoutContext was set on <paramref name="element" /> </returns> public static bool HasTargetSet(DependencyObject element) { if (GetTarget(element) != null || GetTargetWithoutContext(element) != null) { return(true); } #if XFORMS return(false); #else var frameworkElement = element as FrameworkElement; if (frameworkElement == null) { return(false); } return(ConventionManager.HasBinding(frameworkElement, TargetProperty) || ConventionManager.HasBinding(frameworkElement, TargetWithoutContextProperty)); #endif }