DependencyProperty ignores OnPropertyChanged();
- by Kovpaev Alexey
I have PointsListView and PointContainer: INotifyPropertyChanged, ICollection<Point>.
public class PointContainer: INotifyPropertyChanged, ICollection<Point>
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
public IEnumerable<Point> Points
{
get
{
return points.Values;
}
}
public void Clear()
{
points.Clear();
OnPropertyChanged(new PropertyChangedEventArgs("Points"));
}
...
}
For the reliability I made a binding from code:
private void BindPointContainerToListView()
{
Binding binding = new Binding();
binding.Source = PointContainer;
binding.Path = new PropertyPath("Points");
PointsListView.SetBinding(ListView.ItemsSourceProperty, binding);
}
Why when change PointContainer is not automatically updated PointsListView.ItemsSource.
PointsListView.Items.Refresh (); solves the problem, but why does not work automatically? What am I doing wrong?