Enable button based on TextBox value (WPF)

后端 未结 6 1723
無奈伤痛
無奈伤痛 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条回答
  •  萌比男神i
    2021-02-06 03:11

    Try raising CanExecuteChanged when your property changes. The command binding is really distinct from the property binding and buttons bound to commands are alerted to a change in status by the CanExecuteChanged event.

    In your case, you could fire a check when you do the PropertyChanged on the bound property that would evaluate it and set the command's internal CanExecute flag and then raise CanExecuteChanged. More of a "push" into the ICommand object than a "pull".

提交回复
热议问题