Enable button based on TextBox value (WPF)

后端 未结 6 1598
無奈伤痛
無奈伤痛 2021-02-06 02:53

This is MVVM application. There is a window and related view model class.

There is TextBox, Button and ListBox on form. Button is

6条回答
  •  执念已碎
    2021-02-06 03:17

    Since you are using the DelegateCommand, you can call it's RaiseCanExecuteChanged method when your text property changes. I'm not sure what you are trying to accomplish with your CommandReference resource, but typically you just bind the commands directly to the button element's Command property:

    
    

    This would be the relevant portion of your view model:

    public string ObjectName
    {
        get { return objectName; }
        set
        {
            if (value == objectName) return;
            value = objectName;
            AddObjectCommand.RaiseCanExecuteChanged();
            OnPropertyChanged("ObjectName");
        }
    }
    

提交回复
热议问题