I have a TextBox bound to a DateTime using a converter that implements Convert and ConvertBack. UpdateSourceTrigger is set to PropertyChanged so that validation is done as the user types. Here is the problem:
- User types a character
- Converter parses this to a DateTime
- Property in ViewModel is updated and validated
- Converter then converts this DateTime back into a string and changes the string in the text box
This is undesirable as the text can change to a full date while the user has only typed part of a date. How can I stop the UI from doing this? Note that this has only become a problem since upgrading from .NET 3.5 to 4.0 because of this feature:
http://karlshifflett.wordpress.com/2009/05/27/wpf-4-0-data-binding-change-great-feature/
Thanks for any help!
You could use Data Validation, which allows you to check if the typed value fulfills a certain condition (e.g. a regex) before the property gets the typed value -> Converter gets only called if the condition is fulfilled.
Another suggestion would be that you check in your Converter via a regex if the typed value is a DateTime and convert it only if it matches.