You need to validate data in the view model to make this work. If you enabled the ValidatesOnDataErrors property, you need to make the data object an implementation of the IDataErrorInfo interface. Our TextEdit supports all standard validation approaches. Please take a look at the Data Binding MSDN article to learn more about validation.
When a user types anything in the editor, the typed data should pass validation. No matter which of the approaches you will use, if validation fails, the data will not be written to the object's property. Therefore, all validation is performed before the data is inserted. Are you experiencing any trouble implementing one of the validation ways? Which one you're trying to include in your data object?
Thank you for your patience.
Please take a look at the sample text attached before.
I need to validate when a user clicks on update button first (after using add button which makes currentItem a new object)
Because I don't want to insert null values in the database.
So I need something to call validate at update button.
The data object validation is performed as soon as the binding tries to update a value. Since you set the UpdateSourceTrigger property to the "LostFocus" value, validation will be performed as soon as the editor loses focus. After that, depending on how you implemented the validation mechanism, the value will be validated in the data object and if the validation is passed, the value will be assigned to the property.
There is no way to perform validation on demand in this case.
In the "UpdCommand" Execute method, you can check whether the data object has validation errors and decide whether to save it to the database.
Therefore, everything will be implemented in the view model the way you wish.
I've implemented something like here
If you find an easier solution please inform.
Anyway with this solution I have a problem with NullValue and/or TargetNullValue.
If I set them and the editor has a null value it displays the text. but After starting to type some text in TextEdit it remains the NullText and the new text it's appended.
Is it normal ?
I have implemented another approach that is described in the "Data Validation" part of the Data Binding Overview MSDN article. I have created a validation rule and used it in the binding expression. Attached is the modified sample project that illustrates this approach. Data is validated after it is typed in the editor, however it will not be saved until the validation is passed. Anyway, it seems that this conversion is far beyond the bounds of our control usage.
As for NullText, I'm afraid the issue isn't quite clear to me. I have tried to use NullText properties with the validation approach I implemented, but haven't encountered any issue. Please clarify what issue you're talking about.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.