Defines the command behavior binding
Inheritance: IDisposable
Ejemplo n.º 1
0
        //tries to get a CommandBehaviorBinding from the element. Creates a new instance if there is not one attached
        private static CommandBehaviorBinding FetchOrCreateBinding(DependencyObject d)
        {
            CommandBehaviorBinding binding = CommandBehavior.GetBehavior(d);

            if (binding == null)
            {
                binding = new CommandBehaviorBinding();
                CommandBehavior.SetBehavior(d, binding);
            }
            return(binding);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles changes to the Event property.
        /// </summary>
        private static void OnEventChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CommandBehaviorBinding binding = FetchOrCreateBinding(d);

            //check if the Event is set. If yes we need to rebind the Command to the new event and unregister the old one
            if (binding.Event != null && binding.Owner != null)
            {
                binding.Dispose();
            }
            //bind the new event to the command
            binding.BindEvent(d, e.NewValue.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles changes to the Event property.
        /// </summary>
        private static void OnEventChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(d))
            {
                return;
            }

            CommandBehaviorBinding binding = FetchOrCreateBinding(d);

            //check if the Event is set. If yes we need to rebind the Command to the new event and unregister the old one
            if (binding.Event != null && binding.Owner != null)
            {
                binding.Dispose();
            }

            //if (string.IsNullOrEmpty((string)e.NewValue))

            //    return;

            //bind the new event to the command
            binding.BindEvent(d, e.NewValue.ToString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles changes to the Action property.
        /// </summary>
        private static void OnActionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CommandBehaviorBinding binding = FetchOrCreateBinding(d);

            binding.Action = (Action <object>)e.NewValue;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles changes to the Command property.
        /// </summary>
        private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CommandBehaviorBinding binding = FetchOrCreateBinding(d);

            binding.Command = (ICommand)e.NewValue;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets the Behavior property.
 /// </summary>
 private static void SetBehavior(DependencyObject d, CommandBehaviorBinding value)
 {
     d.SetValue(BehaviorProperty, value);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets the Behavior property.  
 /// </summary>
 private static void SetBehavior(DependencyObject d, CommandBehaviorBinding value)
 {
     d.SetValue(BehaviorProperty, value);
 }
Ejemplo n.º 8
0
 //tries to get a CommandBehaviorBinding from the element. Creates a new instance if there is not one attached
 private static CommandBehaviorBinding FetchOrCreateBinding(DependencyObject d)
 {
     CommandBehaviorBinding binding = CommandBehavior.GetBehavior(d);
     if (binding == null) {
         binding = new CommandBehaviorBinding();
         CommandBehavior.SetBehavior(d, binding);
     }
     return binding;
 }