This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
ObjectWrapper has Value and UnderlyingObject property. I would like to use UnderlyingObject in my ValidationRule in order to validate edited value based on other properties so instead of <DataTemplate x:Key='MyEditor'> I tried bind directly to ObjectWrapper <DataTemplate x:Key='MyEditor'> But I got error Error 4 Two-way binding requires Path or XPath |
|
|
What I actually need is bind to Value but somehow access UnderlyingObject from validation rule |
|
|
As I understand it, what your validation rule receives is what the user enters in the text box. Therefore binding to the ObjectWrapper rather than the Value property (or MultiBinding to the UnderlyingObject and Value properties) would not help you: your validation rules would still receive only a string, without any context. Therefore validation rules in WPF are not really intended for the kind of whole-object validation you are talking about here. Whole-object validation is instead handled by implementing IDataErrorInfo or by throwing exceptions from the model object's property setter (because your setter code has access to the entire object). Specify the DataErrorValidationRule or ExceptionValidationRule accordingly; these are given special handling by the binding infrastructure to make this possible. Equivalently, you can set the Binding.ValidatesOnExceptions or ValidatesOnDataError properties. |
|