WPF HierarchicalDataTemplate不会在属性更改时更新ItemsSource [英] WPF HierarchicalDataTemplate doesn't update ItemsSource on property changed

查看:99
本文介绍了WPF HierarchicalDataTemplate不会在属性更改时更新ItemsSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一些XAML

<HierarchicalDataTemplate DataType="{x:Type data:FolderEntity}" 
  ItemsSource="{Binding Path=FolderEntities,UpdateSourceTrigger=PropertyChanged}">
  <Label Content="{Binding FolderName}"/>
</HierarchicalDataTemplate>
<TreeView/>

data:FolderEntity是LINQ to SQL数据类,它实现INotifyPropertyChanging和INotifyPropertyChanged接口。

data:FolderEntity is a LINQ to SQL data class which implements the INotifyPropertyChanging and INotifyPropertyChanged interfaces.

我的问题是,当我更改FolderEntities属性时,绑定不会更新。如果我更改FolderName属性,则与该项目对应的树节点将更改,但是作为FolderEntities的集合将不会更改。

My problem is that when I change the FolderEntities property the binding doesn't update. If I change the FolderName property the tree node that corresponds to that item will change, but the collection that is FolderEntities just wont.

我在考虑WPF检查是否

I'm thinking WPF checks to see whether the collection reference has changed, or does the ItemsSource object have to be an ObservableCollection`1 for this to work?

对此事的任何投入都是值得赞赏的。

Any input on the matter is much appreciated.

推荐答案

是的,基础集合(FolderEntities)将需要为 ObservableCollection< T> 用于通知HierarchicalDataTemplate更改。或者是实现 INotifyCollectionChanged

Yes, the underlying collection (FolderEntities) will need to be an ObservableCollection<T> for the HierarchicalDataTemplate to be notified of the changes. Either that or a collection that implements INotifyCollectionChanged.

这篇关于WPF HierarchicalDataTemplate不会在属性更改时更新ItemsSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆