简体   繁体   English

WPF DataGrid中的颜色单元动态

[英]Color cells in WPF DataGrid dynamically

I populate the contents of a WPF DataGrid with dynamic data that is the result of a search. 我用作为搜索结果的动态数据填充WPF DataGrid的内容。 Now I would like to highlight those cells of the DataGrid, that contain data which was matched during the search. 现在,我要突出显示DataGrid的那些单元格,其中包含在搜索过程中匹配的数据。 Some hints about how this could be achieved are given here . 这里给出一些有关如何实现的提示。 Is there more elegant solution to this problem? 是否有更优雅的解决方案?

Binding to the data is the best way. 绑定数据是最好的方法。 However if the data doesn't have the appropriate values then a converter needs to be employed (as in the examples). 但是,如果数据没有适当的值,则需要使用转换器(如示例中所示)。

if you want something more elegant, I'd add a conversion within the data and bind to that property instead 如果您想要更优雅的东西,我会在数据中添加一个转换并绑定到该属性

say like : 像这样说:

  public int RealProperty { .... }

  public SystemColors.AppWorkspaceColor Colour { return manglefromInt(RealProperty); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM