Enable button based on TextBox value (WPF)

后端 未结 6 1612
無奈伤痛
無奈伤痛 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:21

    Echoing Abe here, but the "right" path to take here is using:

    public void RaiseCanExecuteChanged();
    

    exposed on DelegateCommand. As far as dependencies go, I don't think you're really doing anything "bad" by raising this when the property that the command depends on changes within the ViewModel. In that case, the coupling is more or less contained wholly within the ViewModel.

    So, taking your above example, in your setter for "ObjectName", you would call RaiseCanExecuteChanged on the command "AddObjectCommand".

提交回复
热议问题