Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: PropertyGrid validation is not updated when collection changes [20198]

$
0
0
I have a ObservableCollection<string> property with custom validation done by IDataErrorInfo.

If one of the strings in the collection does not validate, the propertygrid does not show the validation error. If I manually redraw the control (i.e. changing back and forth between tabs in my app) the red box and the validation error info appears.

Validation of simple string properties works correct, the red box is shown immediately.

Version 2.0
Comments: ** Comment from web user: BoucherS **

Hi,

I think I will need a sample to reproduce the issue exactly as you can. Here's a working sample (changing the ObservableCollection updates the PropertyGrid and removes the red Validation Border as expected) :
```
public partial class MainWindow : Window
{
MyClass myClass = new MyClass();

public MainWindow()
{
myClass.FirstName = "Bob";
myClass.MyCollection = new ObservableCollection<string>() { "Apple", "Peanut", "Banana" };
InitializeComponent();

_propertyGrid.SelectedObject = myClass;
}

private void Button_Click( object sender, RoutedEventArgs e )
{
myClass.MyCollection = new ObservableCollection<string>() { "Canada", "USA", "Finland" };
}
}

public class MyClass : IDataErrorInfo, INotifyPropertyChanged
{
public string FirstName
{
get;
set;
}

public ObservableCollection<string> MyCollection
{
get
{
return _myCollection;
}
set
{
_myCollection = value;
this.RaisePropertyChanged( "MyCollection" );
}
}
private ObservableCollection<string> _myCollection;

private void MyCollectionChanged( object sender, NotifyCollectionChangedEventArgs e )
{
}

public string Error
{
get
{
return null;
}
}

public string this[ string propertyName ]
{
get
{
if( propertyName == "MyCollection" )
{
if( this.MyCollection.Contains( "Banana" ) )
return "Collection should not contains Banana.";
}
return null;
}
}

protected void RaisePropertyChanged( string propertyName )
{
if( PropertyChanged != null )
{
PropertyChanged( this, new PropertyChangedEventArgs( propertyName ) );
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
```


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>