样式化Xceed ColumnManagerCell [英] Styling the Xceed ColumnManagerCell

查看:88
本文介绍了样式化Xceed ColumnManagerCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Xceed DataGrid上的列标题样式感兴趣.目的是使背景颜色为灰色,在每个标题列单元格周围具有深灰色边框.在我看来,最好的方法是设置ColumnManager的样式:

I'm interested in styling the column headers on an Xceed DataGrid. The goal is to make the background color grey, with a dark grey border around each header column cell. It seemed to me like the best way to do this was to style the ColumnManager:

<Style TargetType="{x:Type xcdg:ColumnManagerCell}">
    <Setter Property="Template" Value="{StaticResource ColumnManagerCellTemplate}"/>
    <Setter Property="BorderBrush" Value="#c5c5c5"/>
    <Setter Property="BorderThickness" Value="1,1,1,1"/>
</Style>  

使用此模板:

    <ControlTemplate x:Key="ColumnManagerCellTemplate" TargetType="xcdg:ColumnManagerCell">
        <Grid Background="LightGray" >
            <xcdg:DataCell Content="{TemplateBinding Content}"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Center"
                           Background="LightGray"
                           HorizontalContentAlignment="Left"
                           VerticalContentAlignment="Center"
                           BorderBrush="DarkGray"
                           BorderThickness="2"/>
        </Grid>
    </ControlTemplate>

背景颜色和内容一样正确显示,但是我无法在每个单元格周围显示深灰色边框. (或者根本没有颜色边框.)我想念什么? BorderBrush和BorderThickness属性不应该控制吗?它们似乎可以在网格中的其余单元格上工作,但不能在ColumnManagerCells上工作.

The background color shows up correctly, as does the content, but I cannot get a dark grey border to show up around each cell. (Or any color border at all.) What am I missing? Shouldn't the BorderBrush and BorderThickness properties control this? They seem to work on the rest of the cells in the grid, but not the ColumnManagerCells.

推荐答案

您应该使用边框而不是网格,然后为边框连接模板绑定,如下所示:

You should use a border instead of the grid and then hook up the template bindings for the border like this:

<Style TargetType="{x:Type xcdg:ColumnManagerCell}">
    <Setter Property="Background" Value="LightGray" />
    <Setter Property="BorderBrush" Value="#c5c5c5"/>
    <Setter Property="BorderThickness" Value="1,1,1,1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ContentControl">
                <Border Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                    ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                                    ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我应该提到,ColumnManagerCell的默认ControlTemplate是ContentPresenter而不是DataCell,如下所示:

I should mention that my default ControlTemplate for ColumnManagerCell is a ContentPresenter instead of DataCell like below:

<xcdg:DataCell Content="{TemplateBinding Content}" />

确定使用正确的控制模板吗?

Are you sure your using the correct control template?

这篇关于样式化Xceed ColumnManagerCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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