You can use a CellStyleSelector for this task. The CellStyleSelector will let you determine a particular background color depending on the model's values. In fact, the example code in our documentation for CellStyleSelector is exactly what you're trying to do.
However, since you're using AutoGenerateColumns=True, you don't have direct access to the column definition in the markup. It's necessary to set the CellStyleSelector on a column.
Therefore you must hook into the GridView's AutoGeneratingColumn event in order to catch when the column is created for the field and then assign the CellStyleSelector.
if (e.Column != null && e.Column.Name == "StadiumCapacity")
{
e.Column.CellStyleSelector = this.Resources["MyStadiumCapacityStyleSelector"] as StadiumCapacityStyleSelector;
}
}
MVVM Approach
Since you don't want this to happen in the code behind of the page, you could use an EventToCommand behavior. The important part here is that you set PassEventArgsToCommand="True"
Here is an example of setting the behavior and the command in the view model:
I've attached my demo app for the MVVM approach. In order to run the demo you'll need to restore the Telerik DLLs, you can do this with the Upgrade Wizard or manually fixing the references.
Thank you for contacting Support and for choosing Telerik by Progress.
Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!