예제 #1
0
        public ButtonBinder(Button button, IRelayCommand command,
                            Func <object> getParameter = null, bool bindName      = true,
                            ToolTip toolTip            = null, string toolTipText = null)
        {
            _button       = button;
            _command      = command;
            _getParameter = getParameter;
            _bindName     = bindName;
            _toolTip      = toolTip;
            _toolTipText  = toolTipText;

            _button.Enabled = _command.CanExecute(getParameter?.Invoke());
            if (_bindName)
            {
                _button.Text = _command.Name;
            }
            toolTip?.SetToolTip(_button, toolTipText ?? _command.Name);

            _button.Click += OnButtonClick;
            _command.CanExecuteChanged += OnCommandCanExecuteChanged;
            _command.PropertyChanged   += OnCommandPropertyChanged;
            _button.Disposed           += OnButtonDisposed;
        }
예제 #2
0
 private void OnCommandCanExecuteChanged(object sender, EventArgs e)
 {
     _button.Enabled = _command.CanExecute(_getParameter?.Invoke());
 }