Currently I'm Using the IDataErrorInfo but the problem is that I wanted to use this exact code validation for all the textBoxes, now what is happen that if I type a not valid data for the textBox1 box all the textBox2also are getting red border.
I don't want to use specific case for all the text boxes (I have more the 15...) since everything in the validation should be the same for all the text boxes. How should I divide it?
publicstringError{get{thrownewNotImplementedException();}}publicstringthis[string columnName]{get{var error ="";switch(columnName){case"ListItem":if(ListItem!=null){var list =newList<String>{"FirstName","LastName","BusinessItem","BusinessItems"};string value =ListItem.Trim();var isValid =true;if(!string.IsNullOrEmpty(value)){
isValid = list.Contains(value);if(!isValid){
error ="Please enter either FirstName, LastName, BusinessItem, or BusinessItems";}}}break;}return error;}}publiceventPropertyChangedEventHandlerPropertyChanged;}
Xaml
<TextBoxname="textBox1"Text="{Binding Path=ListItem,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"HorizontalAlignment="Center"VerticalAlignment="Center"Width="200"/><TextBoxname="textBox2"Text="{Binding Path=ListItem,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"HorizontalAlignment="Center"VerticalAlignment="Center"Width="200"/
<TextBoxname="textBox3"Text="{Binding Path=ListItem,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"HorizontalAlignment="Center"VerticalAlignment="Center"Width="200"/
....
I wanted to avoid such solution since the validation is the same for all the textBoxes
switch(columnName){case"ListItem1":case"ListItem2":...}
public string ListItem1
{
get { return _item; }
set
{
_item = value;
OnPropertyChanged("ListItem1");
}
}
public string ListItem2
{
get { return _item; }
set
{
_item = value;
OnPropertyChanged("ListItem2");
}
}