Activate WPF command based on TextBox value

Posted by zendar on Stack Overflow See other posts from Stack Overflow or by zendar
Published on 2010-03-11T18:53:20Z Indexed on 2010/03/11 18:54 UTC
Read the original article Hit count: 164

Filed under:
|
|

This is MVVM application. I have form and related view model class.

There is TextBox, Button and ListBox on form. Button is bound to DelegateCommand that has CanExecute function. Idea is that user enters some data in text box, presses button and data is appended to list box.

I would like to enable command (and button) when user enters correct data in TextBox. Things look like this now:

  • CanExecute() contains code that checks if data in property bound to text box is correct.
  • Text box is bound to property in view model
  • UpdateSourceTrigger is set to PropertyChanged and property in view model is updated after each key user presses.

Problem is that CanExecute() does not fire when user enters data in text box. It doesn't fire even when text box lose focus.

How could I make this work?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about command