예제 #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);
            }
        }
예제 #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;
        }
예제 #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);
        }
예제 #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
        }
예제 #5
0
파일: View.cs 프로젝트: tfreitasleal/MvvmFx
        /// <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
        }
예제 #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));
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #9
0
파일: View.cs 프로젝트: tfreitasleal/MvvmFx
 /// <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;
 }