I want to change background color of Datagrid header in Silverlight.
相关问题
- how to Enumerate local fonts in silverlight 4
- Free Silverlight mapping with Bing maps and OpenSt
- Custom number picker?
- Error using ResourceDictionary in Silverlight
- Can we create a Silverlight Socket Server ONLY usi
相关文章
- New Windows Application - What language?
- Unreasonable WPF DataGrid Loading Time
- How to programmatically access a datagrid row deta
- relative url in wcf service binding
- Embedded images not showing when in a UserControl
- Add custom tooltip to row in DataGrid
- How to disable the 'Select All' button of
- DataGrid cell single click edit mode in wpf c#?
Although the DataGrid does not expose a Header Background property, it does have a property for the ColumnHeaderStyle. Using the technique that DaniCE has previously suggested for a single column we can replace the header template for all header columns including the empty space on the right hand side. The down side with replacing the entire template for a header is that we lose the sorting arrows and separators which are present in the default header template. Fortunately we can use a template browser to extract the default template being used and then modify a copy of it.
Here I've thrown together a quick example that will change the background of the column headers to LightBlue while keeping the separators and sorting. Take a look at the default DataGridColumnHeader template in a template browser to see how to deal with modifying the Background when the mouse hovers over the ColumnHeader.
Hope this helps!
I came up with a "Clean" solution.. Hopefully it works for you. I simply override the DataGrid and I exposed the GetTemplateChild method. Using it you can access the DataGridColumnHeaderPresenter and the DataGridColumnHeaders contained in it...
1) Override datagrid
2) Change the background
DataGridEx grid = new DataGridEx();
... after the template is applied ...
DataGridColumnHeadersPresenter obj = DataGrid.GetTemplateObject("ColumnHeadersPresenter") as DataGridColumnHeadersPresenter;
DataGridColumnHeader h = obj.Children[0] as DataGridColumnHeader;
h.Background = new SolidColorBrush(Colors.Red);