当 ItemsSource 应用了转换器时强制 DataGrid 更新
ItemsSource:原始数据的 ObservableCollection。 转换器:通过在 ItemsSource 上应用复杂的非线性变换来生成视图模型。转换器输出是一个简单的列表。
我知道设计是错误的,我应该使用 NotifyPropertyChanged 事件创建视图模型层,但这是一个快速原型,我只是希望有一个简单的技巧可以在 ItemsSource 更新时强制 DataGrid 重新运行转换器。
ItemsSource: an ObservableCollection of raw data.
Converter: generating a view model by applying a complex non-linear transform on ItemsSource. Converter output is a plain list.
I know the design is wrong, I should create view model layer with NotifyPropertyChanged events, but this is a quick prototype for something, I'm just hoping there is an easy trick to force the DataGrid rerun converter whenever ItemsSource updates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的收藏的更改来自哪里 - 按钮?如果它只是一个原型,那么我会使用一个 List,在其之间放置一个 CollectionView 并调用 CollectionView.Refresh() 来显式刷新。
OnPropertyChanged("Data"); 的解决方案看起来它可以循环。
Where does the change to your collection come from - a button? If it is just a prototype then I would use a List, put a CollectionView in between and call CollectionView.Refresh() to refresh explicit.
The solution with OnPropertyChanged("Data"); looks like it could loop.
您可以在集合更改时触发属性级更改通知,这会强制重新评估
ItemsSource
绑定。IE
You can fire property-level change notifications when the collection changes, this forces a reevaluation of the
ItemsSource
binding.i.e.