コード例 #1
0
        public void AddCommandBinding(UserControl control, ICommand command)
        {
            CommandBindingCollection bindings = CommandManager.GetCommandBindings(control);

            if (bindings == null)
            {
                bindings = new CommandBindingCollection();
                CommandManager.SetCommandBindings(control, bindings);
            }
            if (bindings.Where(p => p.Command == command).FirstOrDefault() == null)
            {
                bindings.Add(new CommandBinding(command, CommandExecuted, CommandCanExecute));
            }
        }
コード例 #2
0
 private void CommandExecuted(object sender, ExecutedRoutedEventArgs args)
 {
     args.Command.Execute(args.Parameter);
     //reevaluate CanExecute in order to enable/disable commands
     CommandManager.InvalidateRequerySuggested();
 }