Search code examples
wpfuser-interfacedatagridwpfdatagrid

WPF datagrid - custom colors for each cell


In my application, I build all the rows and columns for a DataGrid programmatically. I would now like to control different UI aspects such as color, font, font size, borders, etc. programmatically for each cell. I am wondering if there is any on-cell-paint event that I can add a callback to and set all the aspects on per-cell basis. An example would be greatly appreciated.

Thank you in advance for your help.


Solution

  • The best solution I found was to capture OnLoadingRow() of DataGrid. The following link shows a working example:

    How to set background of a datagrid cell during AutoGeneratingColumn event depending on its value?