Correct property name for nested property and INotifyDataErrorInfo
Asked Answered
H

1

6

I'm using the INotifyDataError interface for async validation in WPF. I have a property

<TextBox Grid.Column="5" 
         Text="{Binding XXX.Name, ValidatesOnNotifyDataErrors=True}"/>

On my view model I have a property

public SomeType XXX

and on the type SomeType I have the property

public string Name

now my ViewModel implements INotifyPropertyChanged and INotifyDataError and validation is done asynchronously in my viewmodel class. SomeType only implements INotifyPropertyChanged.

My questions is this. When I raise ErrorsChanged event with DataErrorsChangedEventArgs(propertyName)) what should the propertyName be. Note my Binding path is XXX.Name. Should propertyName be

  • XXX.Name
  • Name

or something else or do I have to implement INotifyDataErrorInfo in my SomeType class as well which I was hoping not to have to do as I want my validation to stay in the main view model.

Anyway I've tried both above and the textbox is not getting a red box around it though I can verify that the error event is being raised.

Hydrophyte answered 16/10, 2013 at 11:15 Comment(0)
R
2

afaik i would say you have to implement IDataErrorInfo for your property XXX in your SomeType class because you bind to it. i do this in my projects and it works.

Reggie answered 16/10, 2013 at 11:26 Comment(2)
But what if it is a class you can't implement INotifyDataErrorInfo for. For arguments sake let's say the standard Point class. If I have an individual text box for the X and the Y fields respectively how would I provide validation feedback via INotifyDataErrorInfo?Hydrophyte
create a wrapper class?Reggie

© 2022 - 2024 — McMap. All rights reserved.