예제 #1
0
 public static void SetCommandBinding(CommandBindingCollection commandCollection, ICommand command, 
     ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute = null)
 {
     var binding = (canExecute == null)
         ? new CommandBinding(command, executed)
         : new CommandBinding(command, executed, canExecute);
     commandCollection.Remove(binding);
     commandCollection.Add(binding);
 }
예제 #2
0
 private static void CheckCommandBinding(
     TextBox textBox, TextCommandFlags textCommandFlags,
     IEnumerable<CommandBinding> commandBindings, CommandBindingCollection commandBindingCollection,
     RoutedUICommand command, TextCommandFlags commandFlag, TextCommandType commandType)
 {
     var commandBinding = commandBindings.FirstOrDefault(cb => cb.Command == command);
     if (textCommandFlags.HasFlag(commandFlag) && commandBinding == null)
     {
         commandBindingCollection.Add(TextCommandBindings.CreateCommandBinding(textBox, commandType));
     }
     else if (!textCommandFlags.HasFlag(commandFlag) && commandBinding != null)
     {
         commandBindingCollection.Remove(commandBinding);
     }
 }