DataGrid for WPF includes ComponentOne's unique ClearStyle technology that enables you to change the entire appearance of the grid simply and flawlessly. The following steps will detail how to set the C1DataGrid.Background property to completely change the appearance of the grid. For more details about ComponentOne's ClearStyle technology, see the C1DataGrid ClearStyle topic.
At Design Time
To change the grid's foreground and background color so that it appears green, complete the following steps:
In XAML
For example to change the grid's foreground and background color so that it appears green, add to the <c1:C1DataGrid> tag so that it appears similar to the following:
<c1:C1DataGrid Name="c1datagrid1" Height="180" Width="250" Background="Green" Foreground="White" />
In Code
For example, to change the grid's foreground and background color so that it appears green, add the following code to your project:
Visual Basic |
Copy Code
|
---|---|
Me.C1DataGrid1.Background = New System.Windows.Media.SolidColorBrush(Colors.Green) Me.C1DataGrid1.ForeGround = New System.Windows.Media.SolidColorBrush(Colors.White) |
C# |
Copy Code
|
---|---|
this.c1DataGrid1.Background = new System.Windows.Media. SolidColorBrush(Colors.Green); this.c1DataGrid1.Foreground = new System.Windows.Media. SolidColorBrush(Colors.White); |
What You've Accomplished
Run the application and observe that the grid now appears green with white text in the grid header.
Note that with the C1DataGrid control's ClearStyle technology, the color of the grid, the grid's scrollbars, and the alternating row background of the grid all changed to reflect the green background. Highlight an item in the grid and notice the mouse hover style did not change; you can customize these styles as well if you choose. See Changing the Grid's Mouse Hover Style for more details.