/// <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 Register(Type hostType, CommandModel commandModel) { CommandManager.RegisterClassCommandBinding(hostType, commandModel.CommandBinding); }
public static void SetCommand(DependencyObject sender, CommandModel command) { sender.SetValue(CommandProperty, command); }
public static void RegisterGesture(Type hostType, CommandModel commandModel, InputGesture inputGesture) { CommandManager.RegisterClassCommandBinding(hostType, commandModel.CommandBinding); CommandManager.RegisterClassInputBinding(hostType, new InputBinding(commandModel.Command, inputGesture)); }