Example #1
0
        public static void BindCommand(this Button button, IFormsCommand command, Func <object, object> param)
        {
            var wrapper = new CommandWrapper(command);

            // button.DataBindings.Add("Text", wrapper, "DisplayName");
            button.DataBindings.Add("Enabled", wrapper, "CanExecute");
            button.Click += (s, e) => wrapper.Execute(param);
        }
Example #2
0
 public CommandWrapper(IFormsCommand command)
 {
     //Allow binding to nullcommands. (no exception)
     if (command != null)
     {
         _command = command;
         _command.CanExecuteChanged += (s, e) =>
         {
             if (PropertyChanged != null)
             {
                 PropertyChanged(this,
                                 new PropertyChangedEventArgs("CanExecute"));
             }
         };
     }
 }