1

I have a DataGrid, where items can be selected. Next to it, there are TextBoxes and other editor controls, which are used to edit the selected item.

I want to have the item in the DataGrid to be updated with the properties that are being edited, even if the currently inserted data is invalid. (User can't save invalid data, can't change selected item during editing and cancellation is working too.)

Can this be done in WPF?

CainKellye
  • 1,475
  • 1
  • 10
  • 10

1 Answers1

3

ValidationRule.ValidationStep gets or sets when the validation rule runs.

Since you want the validation rule to run after the source is updated, you'll want to use ValidationStep.CommittedValue.

See msdn for more details.

V Maharajh
  • 9,013
  • 5
  • 30
  • 31
  • I found that if you use ValidationStep.CommittedValue or ValidationStep.UpdatedValue, the Validate method will get the BindingExpression as the value, not the input. So you have to get the value from the BindingExpression which will give you the source value, that you have to convert with the BindingExpression.Converter, etc. Not so simple... – CainKellye Oct 03 '12 at 14:21
  • @CainKellye, Looks like that issue is addressed [here](http://stackoverflow.com/questions/10342715/validationrule-with-validationstep-updatedvalue-is-called-with-bindingexpressi) – V Maharajh Oct 04 '12 at 18:15
  • Thanx, but I had to create a more difficult solution, that involves two validationRules: first runs with RawProposedValue and stores the validation result to a dictionary, but returns valid. Second runs with CommittedValue and returns the previously stored validation from the dictionary. This way I don't have to deal with conversions and no problems with ValidateOnTargetUpdated set to true. – CainKellye Oct 05 '12 at 12:29