当 ItemsSource 应用了转换器时强制 DataGrid 更新

发布于 2025-01-05 01:13:48 字数 219 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被翻牌 2025-01-12 01:13:49

您的收藏的更改来自哪里 - 按钮?如果它只是一个原型,那么我会使用一个 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.

可是我不能没有你 2025-01-12 01:13:49

您可以在集合更改时触发属性级更改通知,这会强制重新评估 ItemsSource 绑定。

IE

//Data being the ObservableCollection
Data.CollectionChanged += (s,e) => OnPropertyChanged("Data");

You can fire property-level change notifications when the collection changes, this forces a reevaluation of the ItemsSource binding.

i.e.

//Data being the ObservableCollection
Data.CollectionChanged += (s,e) => OnPropertyChanged("Data");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文