Silverlight DataGrid 列绑定到对象不刷新
我已将 DataGrid 绑定到 IEnumerable<对象>。对象具有 EntityCollection<访问>属性,它是名称 Accesses。然后我把这
<sdk:DataGridTextColumn
Binding="{Binding Path=Accesses, Converter={StaticResource AccessesToTextConverter}}"
Header="Access"/>
一切工作正常。但是,当我将 Access 对象添加到视图模型中的 Accesses 时,DataGrid 也不会刷新。为什么? :)
I have bound DataGrid to IEnumerable< Object >. Object has EntityCollection< Access > property and it is name Accesses. Then in I put this
<sdk:DataGridTextColumn
Binding="{Binding Path=Accesses, Converter={StaticResource AccessesToTextConverter}}"
Header="Access"/>
All work fine. But when I add Access object to Accesses in my viewmodel DataGrid does nor refresh. Why? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在将项目添加到 IEnumerable 集合中,数据网格不会对其执行任何操作。绑定到的集合必须实现 INotifyCollectionChanged 才能使数据网格自动更新。
如果您使用的集合将 RIA 服务结果保存为对象集合中的属性,并指定为 ItemsSource,请确保将 CollectionChanged 事件连接到对象的 PropertyChanged 事件,如下所示:
You are adding items to a IEnumerable collection which the datagrid will not do anything with. Your collection you bind to must implement INotifyCollectionChanged for the datagrid to automatically update.
If you are using a collection which holds your RIA services results as a property in an object collection that gets assigned as your ItemsSource, make sure you hookup the CollectionChanged event to the PropertyChanged event of your object like so:
您需要为模式指定 TwoWay,以便从代码更新 UI:
You need to specify TwoWay for the mode in order to update the UI from the code for one thing: