/// <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(); }
public static void SetCommand(DependencyObject sender, CommandModel command) { sender.SetValue(CommandProperty, command); }