How to implement IDataErrorInfo to bind indexer strings?

Using xaml (note the binding to the Attributes [Welcome] dictionary entry):

  <Grid x: Name = "LayoutRoot"> <StackPanel> <TextBlock FontSize = "36" FontWeight = "Bold" Foreground = "Purple" Text = "{Binding Attributes [Welcome]}" VerticalAlignment = "Center" HorizontalAlignment = "Center "TextWrapping =" Wrap "/> <TextBox Text =" {Binding Attributes [Welcome], Mode = TwoWay, ValidatesOnDataErrors = True} "> </TextBox> <TextBox Text =" {Binding Attributes [Welcome], Mode = TwoWay, ValidatesOnDataErrors = True} "> </TextBox> <TextBox Text =" {binding test, Mode = TwoWay, ValidatesOnDataErrors = True} "> </TextBox> <TextBox Text =" {binding test, Mode = TwoWay, ValidatesOnDataErrors = True} "> </TextBox> </StackPanel> </ Grid> 
When the view model implements IDataErrorInfo as:
public string Error { get { return ""; } } public string this[string columnName] { get { return "Compulsory Error"; } } 

Only columnName == "Test" is always passed. And so I get the following application: enter image description here
How can I check the values ​​given for an attribute dictionary?

+4
source share
2 answers

I realized that I need to implement IDataErrorInfo in the dictionary, not in the viewmodel containing the dictionary. But since the IDataErrorInfo member conflicts with IDicitonary. I have finished implementing INotifyDataErrorInfo.

0
source

Instead of using a dictionary more, β€œMVVMish” will create a simple ViewModel for the items you are about to display in your list. Then add them to the list (instead of the dictionary) and bind to these elements. You can then implement IDataErrorInfo in these ViewModels models (along with any other custom logic or something else you need).

0
source

All Articles