Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the handler the first time the elements's LayoutUpdated event fires.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        public static void ExecuteOnLayoutUpdated(FrameworkElement element, LayoutEventHandler handler)
        {
            LayoutEventHandler onLayout = null;

            onLayout = (s, e) =>
            {
                handler(s, e);
                element.Layout -= onLayout;
            };
            element.Layout += onLayout;
        }
Ejemplo n.º 3
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="controlName">The name of the 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, string controlName,
                                         string propertyName, BindingMode bindingMode)
        {
            var control = _namedElements.FindName(controlName);

            if (control == null)
            {
                return;
            }

            BindParameter(target, parameter, control, propertyName, bindingMode);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
        public static bool ExecuteOnLoad(FrameworkElement element, EventHandler handler)
        {
#if WEBGUI
            handler(element, new EventArgs());
            return(true);
#else
            if (element.IsHandleCreated)
            {
                handler(element, new EventArgs());
                return(true);
            }

            EventHandler loaded = null;
            loaded = (s, e) =>
            {
                handler(s, e);
                element.HandleCreated -= loaded;
            };

            element.HandleCreated += loaded;
            return(false);
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="handler">The handler.</param>
        /// <returns>true if the handler was executed immediately; false otherwise</returns>
        public static bool ExecuteOnLoad(FrameworkElement element, EventHandler handler)
        {
#if WEBGUI
            handler(element, new EventArgs());
            return true;
#else
            if (element.IsHandleCreated)
            {
                handler(element, new EventArgs());
                return true;
            }
            
            EventHandler loaded = null;
            loaded = (s, e) =>
            {
                handler(s, e);
                element.HandleCreated -= loaded;
            };

            element.HandleCreated += loaded;
            return false;
#endif
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Determines whether a view should have conventions applied to it.
        /// </summary>
        /// <param name="view">The view to check.</param>
        /// <returns>Whether or not conventions should be applied to the view.</returns>
        public static bool ShouldApplyConventions(FrameworkElement view)
        {
            var overriden = View.GetApplyConventions(view.GetDependencyObject());

            return(overriden.GetValueOrDefault(ApplyConventionsByDefault));
        }
Ejemplo n.º 7
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))
            {
                propertyName = ConventionManager.GetElementConvention(control.GetType()).ParameterProperty;
            }

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

                parameter.BindingManager.Bindings.Add(binding);
            }
        }
Ejemplo n.º 8
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="controlName">The name of the 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, string controlName,
            string propertyName, BindingMode bindingMode)
        {
            var control = _namedElements.FindName(controlName);
            if (control == null)
                return;

            BindParameter(target, parameter, control, propertyName, bindingMode);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Executes the handler the first time the elements's LayoutUpdated event fires.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="handler">The handler.</param>
 public static void ExecuteOnLayoutUpdated(FrameworkElement element, LayoutEventHandler handler)
 {
     LayoutEventHandler onLayout = null;
     onLayout = (s, e) =>
     {
         handler(s, e);
         element.Layout -= onLayout;
     };
     element.Layout += onLayout;
 }