在这里,我将一个快速示例放在一起,它将列标题的背景更改为lightBlue,同时保留分隔符和排序.查看template browser中的默认DataGrIDColumnheader模板,了解当鼠标悬停在Columnheader上时如何处理修改背景.
DataGrid Header Background http://i34.tinypic.com/2q2ixch.jpg
<data:DataGrID x:name="grID"> <data:DataGrID.ColumnheaderStyle> <Style xmlns:primitives="clr-namespace:System.windows.Controls.Primitives;assembly=System.windows.Controls.Data" xmlns:vsm="clr-namespace:System.windows;assembly=System.windows" targettype="primitives:DataGrIDColumnheader" > <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="primitives:DataGrIDColumnheader"> <GrID name="Root"> <vsm:visualstatemanager.VisualStateGroups> <vsm:VisualStateGroup x:name="SortStates" > <vsm:VisualStateGroup.Transitions> <vsm:VisualTransition GeneratedDuration="00:00:0.1" /> </vsm:VisualStateGroup.Transitions> <vsm:VisualState x:name="Unsorted" /> <vsm:VisualState x:name="SortAscending"> <Storyboard> <DoubleAnimation Storyboard.Targetname="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" /> </Storyboard> </vsm:VisualState> <vsm:VisualState x:name="SortDescending"> <Storyboard> <DoubleAnimation Storyboard.Targetname="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" /> <DoubleAnimation Storyboard.Targetname="SortIcontransform" Storyboard.TargetProperty="ScaleY" Duration="0" To="-.9" /> </Storyboard> </vsm:VisualState> </vsm:VisualStateGroup> </vsm:visualstatemanager.VisualStateGroups> <GrID.RowDeFinitions> <RowDeFinition Height="*" /> <RowDeFinition Height="*" /> <RowDeFinition Height="auto" /> </GrID.RowDeFinitions> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="auto" /> <ColumnDeFinition WIDth="*" /> <ColumnDeFinition WIDth="auto" /> </GrID.ColumnDeFinitions> <Rectangle x:name="BackgroundRectangle" Stretch="Fill" Fill="lightBlue" GrID.ColumnSpan="2" GrID.rowspan="2" /> <ContentPresenter GrID.rowspan="2" Content="{TemplateBinding Content}" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" margin="{TemplateBinding padding}" /> <Rectangle name="VerticalSeparator" GrID.rowspan="2" GrID.Column="2" WIDth="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" /> <Path GrID.rowspan="2" name="SortIcon" RendertransformOrigin=".5,.5" HorizontalAlignment="left" VerticalAlignment="Center" Opacity="0" GrID.Column="1" Stretch="Uniform" WIDth="8" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z "> <Path.Fill> <SolIDcolorBrush color="#FF444444" /> </Path.Fill> <Path.Rendertransform> <transformGroup> <Scaletransform x:name="SortIcontransform" ScaleX=".9" ScaleY=".9" /> </transformGroup> </Path.Rendertransform> </Path> </GrID> </ControlTemplate> </Setter.Value> </Setter> </Style> </data:DataGrID.ColumnheaderStyle></data:DataGrID>
希望这可以帮助!
总结以上是内存溢出为你收集整理的在Silverlight中更改Datagrid标头的背景颜色全部内容,希望文章能够帮你解决在Silverlight中更改Datagrid标头的背景颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)