Binding DataContext to ValidationRule

前端 未结 7 1926
粉色の甜心
粉色の甜心 2021-02-04 11:33

I have a custom ValidationRule that requires access to the ViewModel in order to validate a supplied value in conjunction with other properties of the ViewModel. I previously tr

7条回答
  •  执念已碎
    2021-02-04 12:13

    I have just found a perfect answer!

    If you set the ValidationStep property of the ValidationRule to ValidationStep.UpdatedValue, the value passed to the Validate method is actually a BindingExpression. You can then interrogate the DataItem property of the BindingExpression object to get the model to which the Binding is bound.

    This means that I can now validate the value that has been assigned along with the existing values of other properties as I want.

提交回复
热议问题