/// <summary> /// Creates the page. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The context.</param> /// <returns></returns> public virtual Page CreatePage(object rootModel, object context) { var view = EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, context)); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, Page.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(Page.TitleProperty, binding); } var activatable = rootModel as IActivate; if (activatable != null) { activatable.Activate(); } var deactivatable = rootModel as IDeactivate; if (deactivatable != null) { view.Unloaded += (s, e) => deactivatable.Deactivate(true); } return(view); }
public override object GetView(object context = null) { if (context == null) { return(base.GetView(context)); } else { //1. Create corresponding ManagedContent. DockType type = (DockType)context; ManagedContent mc; if (type == DockType.Document) { mc = new DocumentContent(); Type = DockType.Document; } else { mc = new DockableContent(); (mc as DockableContent).HideOnClose = true; StateChangedEventManager.AddListener(mc as DockableContent, this); } mc.Content = base.GetView(null); mc.Name = Name; mc.IsCloseable = true; if (!ConventionManager.HasBinding(mc, ManagedContent.TitleProperty)) { mc.SetBinding(ManagedContent.TitleProperty, "DisplayName"); } if (!ConventionManager.HasBinding(mc, ManagedContent.IconProperty)) { Binding bind = new Binding("Icon") { Converter = ImgaeSourceResourceConverter.Default }; mc.SetBinding(ManagedContent.IconProperty, bind); } //2. Create Conductor to manage life cycle new ManagedContentConductor(this, mc); return(mc); } }
///<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); } var frameworkElement = element as FrameworkElement; if (frameworkElement == null) { return(false); } return(ConventionManager.HasBinding(frameworkElement, TargetProperty) || ConventionManager.HasBinding(frameworkElement, TargetWithoutContextProperty)); }
/// <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> /// <returns>The window.</returns> protected virtual Window CreateWindow(object rootModel, bool isDialog, object context) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(Window.TitleProperty, binding); } new WindowConductor(rootModel, view); return(view); }