Example #1
0
        /// <summary>
        /// Callback when the Command property is set or changed.
        /// </summary>
        private static void OnCommandInvalidated(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            // Clear the exisiting bindings on the element we are attached to.
            UIElement element = (UIElement)dependencyObject;

            element.CommandBindings.Clear();

            // If we're given a command model, set up a binding
            CommandModel commandModel = e.NewValue as CommandModel;

            if (commandModel != null)
            {
                element.CommandBindings.Add(new CommandBinding(commandModel.Command, commandModel.OnExecute, commandModel.OnQueryEnabled));
            }

            // Suggest to WPF to refresh commands
            CommandManager.InvalidateRequerySuggested();
        }
Example #2
0
 public static void SetCommand(DependencyObject sender, CommandModel command)
 {
     sender.SetValue(CommandProperty, command);
 }
Example #3
0
 public static void SetCommand(DependencyObject sender, CommandModel command)
 {
     sender.SetValue(CommandProperty, command);
 }