I was wondering how Microsoft did it. In blend, the style of the gridview could not be edited. In 100,000 cases, I had to hand-Write the XAML for processing.
To know how to set the style of a control, it is very important to see the definition of the control class. Let's take a look at how the gridview is defined:
[Styletypedpropertyattribute (property = "columnheadercontainerstyle", styletargettype = typeof (gridviewcolumnheader)] [contentpropertyattribute ("columns")] public class gridview: viewbase, iaddchild
Find two key points from the above definition:
1. Set columnheadercontainerstyle;
Ii. Target type -- gridviewcolumnheader
Okay. With this information, we can easily define the style to the resource.
<Window. resources> <style X: Key = "St" targettype = "gridviewcolumnheader"> <style. setters> <setter property = "background"> <setter. value> <lineargradientbrush startpoint = "0.5, 0" endpoint = "0.5, 1 "> <gradientstop color =" white "offset =" 0 "/> <gradientstop color =" orange "offset =" 1 "/> </lineargradientbrush> </setter. value> </setter> </style. setters> </style> <C: EMPs X: Key = "EPC"/> </window. resources>
Then we define the listview and apply the style to the columnheadercontainerstyle attribute of the gridview.
<Listview itemssource = "{binding source = {staticresource EPC}"> <listview. view> <gridview allowscolumnreorder = "true" columnheadercontainerstyle = "{staticresource st}"> <gridviewcolumn displaymemberbinding = "{binding Path = Name}" header = "employee name"/> <gridviewcolumn displaymemberbinding = "{binding Path = age}" header = "Employee age"/> </gridview> </listview. view> </listview>