public static CommandBindingManager RegisterCommand(this CommandBindingManager cmdBindingManager, BoundCommand command, object sourceObject, string sourceEvent = "Click") { var commandBinding = new CommandBinding(command, sourceObject, sourceEvent); cmdBindingManager.CommandBindings.Add(commandBinding); return cmdBindingManager; }
public static CommandBindingManager RegisterCommand(this CommandBindingManager cmdBindingManager, object source, Action<object> execute, Func<object, bool> canExecute, string sourceEvent = "Click") { var command = new BoundCommand(execute, canExecute, null); var commandBinding = new CommandBinding(command, source, sourceEvent); cmdBindingManager.CommandBindings.Add(commandBinding); return cmdBindingManager; }
private void OnLoad(object sender, EventArgs eventArgs) { try { var commandBindingManager = new CommandBindingManager(); var commandBinding = new CommandBinding(); _saveCommandButton = new BoundCommand(SaveMessage, CanSave, "Button"); commandBinding.SourceObject = Save; commandBinding.SourceEvent = ControlEvent.Click.ToString(); commandBinding.Command = _saveCommandButton; commandBindingManager.CommandBindings.Add(commandBinding); _saveCommandToolStrip = new BoundCommand(SaveMessage, CanSave, "ToolStrip"); commandBindingManager.CommandBindings.Add(new CommandBinding(_saveCommandToolStrip, Tool, ToolStripItemEvent.Click.ToString())); _closeComamand = new BoundCommand(Close, CanClose, null); commandBindingManager.CommandBindings.Add(new CommandBinding(_closeComamand, CloseForm, ControlEvent.Click.ToString())); var bindingManager = new BindingManager(); bindingManager.Bindings.Add(new TypedBinding<MainForm, TextBox>(this, t => t.FullNameText, FullName, s => s.Text)); } catch (Exception e) { MessageBox.Show(e.Message); } }