You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [.NET MAUI DataGrid]({%slug datagrid-overview%}) component exposes a conditional styling feature. It allows users to apply different styles on a cell or per group header depending on a specific condition.
13
13
14
-
You can set a different style on a specific cell from a specific column based on custom selection logic with the following properties:
14
+
## Cell Style Selector
15
+
16
+
You can set a different style on a specific cell from a specific column based on custom style-selection logic with the following properties:
15
17
16
18
*`CellContentStyleSelector`(`IStyleSelector`)—Styles the content of the cell by using the text alignment options (`TextMargin`, `HorizontalTextAlignment`, `VerticalTextAlignment`), the font options (`FontAttributes`, `FontFamily`, `FontSize`) and the `TextColor` property.
17
19
*`CellDecorationStyleSelector`(`IStyleSelector`)—Styles the decoration of a cell.
18
20
19
-
Different styles can be applied on a per-group header once the DataGrid control is grouped through `GroupHeaderStyleSelector` property.
21
+
> For the DataGrid Style Selector example, go to the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and navigate to the **DataGrid > Styling** category.
22
+
23
+
## Row Background Style Selector
24
+
25
+
You can set a different style on a row, alternate row and on row details based on custom style-selection logic by using the `RowBackgroundStyleSelector` (`IStyleSelector`) property.
26
+
27
+
> For the DataGrid Row Background Style Selector example, go to the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and navigate to the **DataGrid > Styling** category.
20
28
21
-
Different styles can be applied on a per-group footer once the DataGrid control is grouped through `GroupFooterStyleSelector` property.
29
+
## Group Style Selector
30
+
31
+
You can set a different style on a group header and footer based on custom style-selection logic with the following properties:
32
+
33
+
*`GroupHeaderStyleSelector`(`IStyleSelector`)—Different styles can be applied on a per-group header once the DataGrid control is grouped
34
+
*`GroupFooterStyleSelector`(`IStyleSelector`)—Different styles can be applied on a per-group footer once the DataGrid control is grouped
22
35
23
36
> To display the group footer, set the `ShowGroupFooters` property to `True`.
24
37
25
-
The `CellContentStyleSelector`, `CellDecorationStyleSelector`, and `GroupStyleSelector` use the `SelectStyle` method to change the style.
38
+
> For the DataGrid Style Selector example, go to the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and navigate to the **DataGrid > Styling** category.
26
39
27
-
## Example
40
+
The `CellContentStyleSelector`, `CellDecorationStyleSelector`, `RowBackgroundStyleSelector`, `GroupHeaderStyleSelectorand`, and `GroupFooterStyleSelector` use the `SelectStyle` method to change the style.
28
41
29
-
The following example will demonstrate how to apply the style selectors in the DataGrid control:
42
+
## Example with Cell and Group Style Selectors
30
43
31
-
Let’s add the DataGrid and set the `CellContentStyleSelector` as a static resource of type `MyCellContentStyleSelector`, `CellDecorationStyleSelector` as a static resource of type `MyCellDecorationStyleSelector`, and `GroupStyleSelector` as a static resource of type `MyGroupStyleSelector`.
44
+
The following example will demonstrate how to apply the style selectors on the DataGrid cell and group header:
32
45
33
-
**1.**`DataGrid` definition in XAML:
46
+
Let’s add the DataGrid and set the `CellContentStyleSelector` property as a static resource of type `MyCellContentStyleSelector`, `CellDecorationStyleSelector` as a static resource of type `MyCellDecorationStyleSelector`, and `GroupStyleSelector` as a static resource of type `MyGroupStyleSelector`.
47
+
48
+
**1.** Define the `RadDataGrid` in XAML:
34
49
35
50
<snippetid='datagrid-styleselector-example'/>
36
51
37
-
**2.** Create a simple data for the DataGrid:
52
+
**2.** Create a sample data model:
38
53
39
54
<snippetid='datagrid-styleselector-data'/>
40
55
41
-
**3.** Set the `ItemsSource` of the `DataGrid` class:
56
+
**3.** Set the `ItemsSource` of the `RadDataGrid`:
42
57
43
58
<snippetid='datagrid-styleselector-items'/>
44
59
60
+
**4.** Create a custom class for each selector. Each class derives from `IStyleSelector` and overrides its `SelectStyle` method.
61
+
62
+
* The implementation of `MyCellContentSelector` class:
45
63
46
-
**4.** Add `MyCellContentStyleSelector`, `MyCellDecorationStyleSelector`, and `MyGroupStyleSelector` as resources in the **Resource** page of the application:
64
+
<snippetid='datagrid-styleselector-cellcontent'/>
65
+
66
+
* The implementation of `MyCellDecorationSelector` class:
**5.** Add `MyCellContentSelector`, `MyCellDecorationSelector`, and `MyGroupSelector` as resources in the **Resource** page of the application:
47
75
48
76
<snippetid='datagrid-styleselectors'/>
49
77
50
-
**5.** Create a custom class for each selector. This class derives from `DataGridStyleSelector` and overrides its `SelectStyle` method.
78
+
This is how the DataGrid control will look when `CellContentStyleSelector` is applied.
51
79
52
-
The `MyCellContentStyleSelector` class implementation is as follows:
80
+

53
81
54
-
<snippetid='datagrid-styleselector-cellcontent'/>
82
+
> For the DataGrid Style Selector example, go to the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and navigate to the **DataGrid > Styling** category.
55
83
56
-
The implementation of the `MyCellDecorationStyleSelector` class is shown below:
> For the DataGrid Row Background Style Selector example, go to the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and navigate to the **DataGrid > Styling** category.
Copy file name to clipboardExpand all lines: controls/datagrid/theming-and-styles/styling.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ The next image shows the end result.
35
35
You can style the rows and cells of the DataGrid with the following properties:
36
36
37
37
*`RowBackgroundStyle`(of type `Style` with target type `DataGridRowBackgroundAppearance`)—Defines the style of each row.
38
-
*`AlternateRowBackgroundStyle`(of type `Style` with target type `DataGridAlternateRowBackgroundAppearance`)—Defines the appearance style of an alternated row.
38
+
*`AlternateRowBackgroundStyle`(of type `Style` with target type `DataGridRowBackgroundAppearance`)—Defines the appearance style of an alternated row.
39
39
*`SelectionStyle`(of type `Style` with target type `DataGridSelectionAppearance`)—Defines the appearance settings applied to the selected DataGrid row.
40
40
*`CurrentCellStyle`(of type `Style` with target type `DataGridCurrentCellAppearance`)—Defines the style applied to the current cell.
41
41
* (Desktop-only)`MouseHoverStyle`(of type `Style` with target type `DataGridMouseHoverAppearance`)—Specifies the style applied to the cells and rows when the mouse is over them.
0 commit comments