DependencyProperty ignores OnPropertyChanged();
Posted
by
Kovpaev Alexey
on Stack Overflow
See other posts from Stack Overflow
or by Kovpaev Alexey
Published on 2011-11-14T21:39:14Z
Indexed on
2011/11/15
1:52 UTC
Read the original article
Hit count: 495
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?
© Stack Overflow or respective owner