WPF - Bound treeview not updating root items

后端 未结 2 1899
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 10:31

I\'m using a WPF TreeView control, which I\'ve bound to a simple tree structure based on ObservableCollections. Here\'s the XAML:




        
2条回答
  •  心在旅途
    2021-01-24 10:59

    You are setting ItemsSource = root which happens to implement IEnumerable but is not in and of itself observable. Even though you have a Children property which is observable, that's not what you're binding the TreeView to so the TreeView doesn't have any way of listening to changes that occur through the Children property.

    I would drop IEnumerable from the Node class altogether. Then set treeView.ItemsSource = root.Children;

提交回复
热议问题