如何在WPF Datagrid上格式化标题? [英] How do I format headers on a WPF Datagrid?

查看:200
本文介绍了如何在WPF Datagrid上格式化标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeplex的WPF Datagrid。



我可以在dg:DataGrid元素中对行进行样式化和以下属性。



但是,如何对标题进行风格化?我找到了100个在网页上的例子,这些例子定义了样式,并使用例如x:Key =DataGridColumnHeaderStyle在Datagrid元素,但它们似乎都不适合我。



将Datagrid头文件背景更改为橙色的DataGrid?

 < dg:DataGrid AlternatingRowBackground =#ddd
RowBackground =#eee
Name =theGrid1
VerticalAlignment =Stretch
AutoGenerateColumns =False
BorderBrush =#ddd>
...
< / dg:DataGrid>


解决方案

这种情况下的样式在一个名为generic .xaml它应该在你的项目的一个themems文件夹中。



找到它并打开它。里面你会发现这一行控制列标题的背景

 < dg:DataGridHeaderBorder SortDirection ={TemplateBinding SortDirection} 
IsHovered ={TemplateBinding IsMouseOver}
IsPressed ={TemplateBinding IsPressed}
IsClickable ={TemplateBinding CanUserSort}
Background ={TemplateBinding Background}
BorderBrush ={TemplateBinding BorderBrush}
BorderThickness ={TemplateBinding BorderThickness}
Padding ={TemplateBinding Padding}
SeparatorVisibility ={TemplateBinding SeparatorVisibility}


SeparatorBrush ={TemplateBinding SeparatorBrush}>

基本上它在模板中的另一个位置定义:
这将向您介绍TemlateBinding
MSDN TemplateBinding



HTH,
Eric


I am using the WPF Datagrid from Codeplex.

I am able to style the rows and with the following attributes in the dg:DataGrid element.

But how do I style the Headers? I find 100s of examples on the web which define Styles and use e.g. x:Key="DataGridColumnHeaderStyle" in the Datagrid element, but none of them seem to work for me.

How can I just e.g. change the Datagrid Header background to orange on this DataGrid?

<dg:DataGrid AlternatingRowBackground="#ddd" 
    RowBackground="#eee" 
    Name="theGrid1" 
    VerticalAlignment="Stretch" 
    AutoGenerateColumns="False" 
    BorderBrush="#ddd">
...
</dg:DataGrid>

解决方案

The style in this case is in a file called generic.xaml it should be loacted in a themems folder in your project.

find it and open it. inside you will find this line that controls the background of the column headers

 <dg:DataGridHeaderBorder SortDirection="{TemplateBinding SortDirection}"
                                     IsHovered="{TemplateBinding IsMouseOver}"
                                     IsPressed="{TemplateBinding IsPressed}"
                                     IsClickable="{TemplateBinding CanUserSort}"
                                     Background="{TemplateBinding Background}"
                                     BorderBrush="{TemplateBinding BorderBrush}"
                                     BorderThickness="{TemplateBinding BorderThickness}"
                                     Padding ="{TemplateBinding Padding}"
                                     SeparatorVisibility="{TemplateBinding SeparatorVisibility}"


                         SeparatorBrush="{TemplateBinding SeparatorBrush}">

basically its defined at another place in the template: this will explain TemlateBinding to you MSDN TemplateBinding

HTH, Eric

这篇关于如何在WPF Datagrid上格式化标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆