I have a simple treeview. The itemtemplate has a check box. When the checkbox is clicked, my model updated all children to reflect the same checked state as the parent. This works in code but is not reflected on the tree. I’ve even added a ton of callbakcs, property change notifications, etc.
public class OutlookFolder : INotifyPropertyChanged
{
public delegate void CollectionChangedDelegate();
public static CollectionChangedDelegate CollectionChanged;
public string Name { get; set; }
public string ID { get; set; }
private bool _checked;
public bool Checked
{
get { return _checked; }
set { _checked = value; UpdateChildren(value); }
}
private ObservableCollection<OutlookFolder> _Children;
public ObservableCollection<OutlookFolder> Children
{
get { return _Children; }
set { _Children = value; OnPropertyChanged("Children"); }
}
private void UpdateChildren(bool value)
{
if (Children == null) { return; }
foreach (OutlookFolder f in Children)
{
f.Checked = value;
}
if (CollectionChanged != null)
{
CollectionChanged.Invoke();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
As you can see I even added a delegate that I call after updating the children list which causes the viewmodel to also call OnPropertyChange()
Does your OutlookFolder object implement PropertyChanged when you change Checked? Collectionchanged doesn’t update individual items only the treeview.