.NET MAUI TreeDataGrid Style Selectors
The .NET MAUI TreeDataGrid component exposes a conditional styling feature. It allows you to define specific conditions and apply distinctive styles to a cell or a group header.
Cell Style Selector
You can set a distinct style to a specific cell in a given column based on custom style-selection logic with the following properties:
-
CellContentStyleSelector
(IStyleSelector
)—Styles the content of the cell by using the text alignment options (TextMargin
,HorizontalTextAlignment
,VerticalTextAlignment
), the font options (FontAttributes
,FontFamily
,FontSize
), and theTextColor
property. -
CellDecorationStyleSelector
(IStyleSelector
)—Styles the decoration of a cell.
As the TreeDataGrid inherits from the DataGrid control, for Style Selector example, go to the SDKBrowser Demo Application and navigate to the DataGrid > Styling category.
Row Background Style Selector
You can set a different style on a row, an alternate row, and on row details based on custom style-selection logic by using the RowBackgroundStyleSelector
(IStyleSelector
) property.
To apply a RowBackgroundStyleSelector
you have to:
- Create a custom class that inherits from
IStyleSelector
. - Implement the
SelectStyle
method.
The object item of the SelectStyle
method is of type DataGridRowInfo
. The DataGridRowInfo
represents a class that provides information for each row in DataGrid and exposes the following properties:
-
Item
(object
)—Gets the business object associated with the row. -
IsRowDetails
(bool
)—Gets a value that specifies whether the row is aRowDetail
. -
IsAlternate
(bool
)—Gets a value that specifies whether the row is an alternate one.
As the TreeDataGrid inherits from the DataGrid control, for Row Background Style Selector example, go to the SDKBrowser Demo Application and navigate to the DataGrid > Styling category.