开发者

DataGridCell.Template Style overriding IsSelected Trigger

Why does the IsSelected Trigger below only work when Template Setter is absent from the code? How can I get both to function as expected?

I have the following in my Application.Resources tag;

<Style TargetType="{x:Type DataGridCell}">
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                &l开发者_如何学JAVAt;ContentPresenter VerticalAlignment="Center"></ContentPresenter>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


When you re-template the DataGridCell you also lose the border that is actually the control that draws the Background. Add this and it'll work.

<Style TargetType="{x:Type DataGridCell}">
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border Background="{TemplateBinding Background}">
                    <ContentPresenter VerticalAlignment="Center"></ContentPresenter>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜