Esempio n. 1
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="control">The actual control to bind to.</param>
        /// <param name="propertyName">The name of the property to bind to.</param>
        /// <param name="bindingMode">The binding mode to use.</param>
        public static void BindParameter(FrameworkElement target, Parameter parameter, FrameworkElement control,
                                         string propertyName, BindingMode bindingMode)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                var convention = ConventionManager.GetElementConvention(control.GetType());
                if (convention != null)
                {
                    propertyName = convention.ParameterProperty;
                }
            }

            if (!string.IsNullOrEmpty(propertyName))
            {
                var binding = new Binding()
                {
                    SourceObject = control,
                    SourcePath   = propertyName,
                    TargetObject = parameter,
                    TargetPath   = "Value",
                    Mode         = bindingMode
                };

                parameter.BindingManager.Bindings.Add(binding);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a Form.
        /// </summary>
        /// <param name="rootModel">The root view model.</param>
        /// <param name="isDialog">if set to <c>true</c> the Form is a dialog.</param>
        /// <param name="context">The view context.</param>
        /// <param name="settings">The optional popup settings.</param>
        /// <param name="rootForm">The root form.</param>
        /// <returns>The created Form.</returns>
        /// <remarks>
        /// The calling method only passes the root form parameter in ShowMainWindow, when the main form already exists.
        /// This is necessary for Visual WebGUI (or Windows if the Bootstrapper is invoked after the main form creation).
        /// </remarks>
        protected virtual Page CreatePage(object rootModel, bool isDialog, object context,
                                          IDictionary <string, object> settings, Page rootForm = null)
        {
            Page view;

            if (rootForm != null)
            {
                view = rootForm;
            }
            else
            {
                view = EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, null), isDialog);
            }

            ViewModelBinder.Bind(rootModel, view, null);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, "Text"))
            {
                view.DataBindings.Add(new Binding("Text", rootModel, "DisplayName", true,
                                                  DataSourceUpdateMode.OnPropertyChanged));
            }

            ApplySettings(view, settings);

            new WindowConductor(rootModel, view);

            return(view);
        }
Esempio n. 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.Object as Control;

            if (frameworkElement == null)
            {
                return(false);
            }

            return(ConventionManager.HasBinding(frameworkElement, TargetProperty) ||
                   ConventionManager.HasBinding(frameworkElement, TargetWithoutContextProperty));
        }
Esempio n. 4
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);
            }
#if WINFORMS || WEBGUI
            var frameworkElement = element.Object as FrameworkElement;
#else
            var frameworkElement = element as FrameworkElement;
#endif
            if (frameworkElement == null)
            {
                return(false);
            }

            return(ConventionManager.HasBinding(frameworkElement, TargetProperty) ||
                   ConventionManager.HasBinding(frameworkElement, TargetWithoutContextProperty));
        }