0

Xceed DataGrid の列ヘッダーのスタイルに興味があります。目標は、背景色を灰色にし、各ヘッダー列のセルの周りに濃い灰色の境界線を付けることです。これを行う最善の方法は、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 では機能しません。

4

1 に答える 1

1

グリッドの代わりにボーダーを使用し、ボーダーのテンプレート バインディングを次のようにフックする必要があります。

<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 は DataCell ではなく ContentPresenter であることに注意してください。

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

正しいコントロール テンプレートを使用していますか?

于 2013-11-08T17:10:43.570 に答える