简体   繁体   中英

Color cells in WPF DataGrid dynamically

I populate the contents of a WPF DataGrid with dynamic data that is the result of a search. Now I would like to highlight those cells of the DataGrid, that contain data which was matched during the search. 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); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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