Datagrid: support for grouping on columns use IValueConverters to display their value and conditonal rowstyling
Introduction
Some further enhancements have been made to the DataGrid wrapper that has been the subject of this previous post:
- Support for grouping on columns that use
IValueConverterto display their value - Conditional row styling
This post is a code drop for these enhancements.
Conditional row styling
The following code gives a sample on how to use conditional row styling:
public MainPage() { InitializeComponent(); theDataGrid.ItemsSource = PersonFactory.GetAllPersons(); theDataGrid.RowStyles.Add(new MyDataGridRowConditionalStyle( (o) => { return ((Person)o).Name.Contains("A"); }, new MyDataGridRowStyle() { Background = new SolidColorBrush(Colors.Yellow), ToolTip = "Name contains an 'A'" } )); theDataGrid.RowStyles.Add(new MyDataGridRowConditionalStyle( (o) => { return ((Person)o).Name.Contains("C"); }, new MyDataGridRowStyle() { Foreground = new SolidColorBrush(Colors.Red), ToolTip = "Name contains a 'C'" } )); theDataGrid.RowStyles.Add(new MyDataGridRowConditionalStyle( (o) => { return ((Person)o).Name.Contains("N"); }, new MyDataGridRowStyle() { FontSize = 14, FontWeight = FontWeights.ExtraBold, ToolTip = "Name contains an 'N'" } )); }
The result can be seen in the picture above
Download
The sources can be downloaded here.
Additional remarks
A solution for conditional cell styling can be found here


Rudy said:
Dec 10, 10 at 7:36 amAwesome!!!!