WPF DataTemplateSelector 标准更改但模板未重新应用?
我有一个应用于 DataGridTemplateColumn 的 DataTemplateSelector。 它正确地为我提供了一个 DataTemplate,该模板根据我的 DataRow(在其他列中)中的某些信息而变化。
到目前为止,一切都很好。
但是,当我现在更改网格中的数据时,这将导致选择器为该列选择不同的 DataTemplate,它不会自动显示这个新的 DataTemplate。
我在 Matthew MacDonald (Apress) 的 Pro WPF in C# 2008 第 564 页中读到,这是已知问题,唯一的解决方法是释放选择器并重新应用它,当我的表中有很多记录时,这会非常慢。
有没有人找到解决这个问题的方法,或者也许在 .NET4 中有一个新功能可以解决这个问题?
谢谢马塞尔
I have a DataTemplateSelector which is applied to a DataGridTemplateColumn.
It is correctly providing me with a DataTemplate that varies depending on certain information in my DataRow (in other columns).
So far so good.
However, when I now alter data in my grid which would cause a different DataTemplate to be chosen by the selector for that column it does NOT automatically show this new DataTemplate.
I read in Pro WPF in C# 2008 by Matthew MacDonald (Apress) page 564 that this is known issue and the only way around is to release the Selector and reapply this which would be very slow when there are many records in my table.
Has anyone found a way around this or maybe in .NET4 there is a new feature that combats this issue?
Thanks
Marcel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种解决方案是将 ContentPresenter 放入单元格内。这样,当内容更改时,ContentPresenter 将再次向选择器请求模板。例如:
和后面的代码:
编辑:我已经删除了我之前的答案,即使用转换器而不是选择器。这确实有效,但我认为这是一个更好的答案。
One solution is to put a ContentPresenter inside the cell. That way when the content changes the ContentPresenter will request the template from the selector again. eg:
and code behind:
Edit: I have removed my previous answer which was to use a converter instead of a selector. That did work but I think this is a better answer.