Continue to chat about WPF -- set a style for the row of listview

Source: Internet
Author: User

 

Key point: you need to set the row style of the listview and the itemcontainerstyle attribute of the listview. However, in this example, you do not need to set this attribute because I apply the style to all listviewitems.
<Window X: class = "wpf_gridheaderstyle_sample.window1" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns: c = "CLR-namespace: wpf_gridheaderstyle_sample "Title =" window1 "Height =" 300 "width =" 300 "> <window. resources> <controltemplate X: Key = "tmpforthumb" targettype = "{X: Type thumb}"> <Border> <rectangle width = "1" name = "REC"> <rectan GLE. fill> <lineargradientbrush startpoint = "0.5, 0.3 "endpoint =" 0.22 "> <gradientstop color =" orange "offset =" "/> <gradientstop color =" white "offset =" 1 "/> </lineargradientbrush> </rectangle. fill> </rectangle> </Border> <controltemplate. triggers> <trigger property = "ismouseover" value = "true"> <setter targetname = "REC" property = "fill" value = "lightgreen"/> </trigger> </ controltemplate. triggers> </contro Ltemplate> <style targettype = "{X: Type gridviewcolumnheader}"> <setter property = "overridesdefaultstyle" value = "true"/> <setter property = "template"> <setter. value> <controltemplate targettype = "{X: Type gridviewcolumnheader}"> <grid name = "G"> <grid. background> <lineargradientbrush startpoint = "0.5, 0" endpoint = "0.5, 1 "> <gradientstop color =" gold "offset =" 0.3 "/> <gradientstop color =" lightyellow "offset =" 1 "/> </Lineargradientbrush> </grid. background> <border name = "BD" padding = "{templatebinding padding}"> <contentpresenter margin = "5, 4, 1, 3 "horizontalalignment =" {templatebinding sequence} "/> </Border> <thumb name =" part_headergripper "template =" {staticresource tmpforthumb} "sequence =" right "margin = ", -1, 0 "/> </GRID> <controltemplate. triggers> <trigger property = "ismouseove R "value =" true "> <setter targetname =" G "property =" background "> <setter. value> <lineargradientbrush startpoint = "0.5, 0" endpoint = "0.5, 1 "> <gradientstop color =" deeppink "offset =" 0.3 "/> <gradientstop color =" white "offset =" 1 "/> </lineargradientbrush> </setter. value> </setter> </trigger> </controltemplate. triggers> </controltemplate> </setter. value> </setter> </style> <! -- Data source --> <C: Students X: Key = "dbsource"/> <! -- Listviewitem style --> <style targettype = "{X: Type listviewitem}"> <style. setters> <setter property = "snapstodevicepixels" value = "true"/> <setter property = "template"> <setter. value> <controltemplate targettype = "{X: Type listviewitem}"> <border X: name = "BD" borderthickness = "1" padding = "{templatebinding padding}" snapstodevicepixels = "true"> <gridviewrowpresenter plugin = "{templatebinding plugin}" margin = "3 "/> </Border> <controltemplate. triggers> <trigger property = "isselected" value = "true"> <trigger. setters> <setter targetname = "BD" property = "background"> <setter. value> <lineargradientbrush startpoint = "0.5, 0.22" endpoint = "0.5, 1 "> <gradientstop color =" lightgray "offset =" 0.31 "/> <gradientstop color =" gray "offset =" 0.88 "/> </lineargradientbrush> </setter. value> </setter> </trigger. setters> </trigger> </controltemplate. triggers> </controltemplate> </setter. value> </setter> </style. setters> </style> </window. resources> <grid> <listview X: Name = "LV" itemssource = "{staticresource dbsource}"> <listview. view> <gridview allowscolumnreorder = "true"> <gridviewcolumn displaymemberbinding = "{binding Path = Name}" header = "name" width = "110"/> <gridviewcolumn displaymemberbinding = "{ binding Path = phone} "header =" contact number "width =" 125 "/> </gridview> </listview. view> </listview> </GRID> </WINDOW>

 

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.