Reputation: 109
I want to change the background of row in datagrid if the value of a row item exceeds a certain value.
Upvotes: 0
Views: 981
Reputation: 44028
This is the way to do it without resorting to procedural code, directly in XAML, which is where styling belongs.
Upvotes: 2
Reputation: 4205
You can do this in the LoadingRow
event, like so:
private void dataGridLoadingRow(object sender, DataGridRowEventArgs e)
{
YourObject rowContext = e.Row.DataContext as YourObject;
if (rowContext != null)
{
if (rowContext.YourValue > _someValue)
e.Row.Background = new SolidColorBrush(Colors.Green);
}
}
Upvotes: 0