Why is the ViewModel not updating when the WPF TextBox is invalid?

Today I looked at an MSDN example to check for WPF TextBox entries (see also: http://msdn.microsoft.com/en-us/library/ms753962.aspx ).

In my own application, I bind the DataContext of the view to the ViewModel using the MVVM template. Some text fields are binding to properties in the ViewModel and have ValidationRules defined for them.

What I discovered is that when a value becomes invalid after it has been successfully verified earlier, the old value will remain in the ViewModel. In my opinion, it is very inconvenient because the values ​​are used to execute the command, for example.

This exact problem of mine applies to this MSDN example. The TextBox value is sent back to the source after successful validation. I would like to keep the validation logic, but it should always update the source. Is it possible?

Thanks in advance.

+5
source share
2 answers

As Rachel and Hank pointed out, this is how WPF validation rules are created. If the validation fails, it will not write the value to the property.

, , , , , , . (, ), . , (, "foo" int). , , " , ".

, , ViewModel , , . - - , "Fort Knox ViewModels" , , . ViewModel " ", " ". , ValidationRules.

+3

, , . , .

, - TextBox, Integer, int, .

IsValid(), true/false, .

+2

All Articles