Continue to chat about WPF -- set the style of the Grid Control Column Title

Source: Internet
Author: User

 

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>
 
 
 
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.