Styling the Xceed ColumnManagerCell

不问归期 提交于 2019-12-06 15:59:53

问题


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>  

Using this template:

    <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>

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.


回答1:


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>

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?



来源:https://stackoverflow.com/questions/19864231/styling-the-xceed-columnmanagercell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!