Used to configure the conventions used by the framework to apply bindings and create actions.
Beispiel #1
0
        /// <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);
            }
        }
Beispiel #3
0
        ///<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));
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <summary>
        /// Creates a binding on a <see cref="Parameter"/>.
        /// </summary>
        /// <param name="target">The target to which the message is applied.</param>
        /// <param name="parameter">The parameter object.</param>
        /// <param name="elementName">The name of the element to bind to.</param>
        /// <param name="path">The path of the element to bind to.</param>
        /// <param name="bindingMode">The binding mode to use.</param>
        public static void BindParameter(FrameworkElement target, Parameter parameter, string elementName, string path, BindingMode bindingMode)
        {
            var element = elementName == "$this"
                ? target
                : BindingScope.GetNamedElements(target).FindName(elementName);

            if (element == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(path))
            {
                path = ConventionManager.GetElementConvention(element.GetType()).ParameterProperty;
            }

            var binding = new Binding(path)
            {
                Source = element,
                Mode   = bindingMode
            };

#if SILVERLIGHT && !SL5
            var expression = (BindingExpression)BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding);

            var field = element.GetType().GetField(path + "Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
            if (field == null)
            {
                return;
            }

            ConventionManager.ApplySilverlightTriggers(element, (DependencyProperty)field.GetValue(null), x => expression, null, null);
#else
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            BindingOperations.SetBinding(parameter, Parameter.ValueProperty, binding);
#endif
        }