从样式访问 ControlTemplate 中的元素

Access Element in ControlTemplate from Style

我想 Style Border 里面 ControlTemplate。但我不知道如何访问它。我的 Style 看起来像这样:

<Style x:Key="RedCell" TargetType="DataGridCell" BasedOn="{StaticResource MYDGCellStyle}">            
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridCell">
                    <Grid>
                        <Grid Grid.ZIndex="86" x:Name="CellContenGrind" Background="{TemplateBinding Background}" />                            
                        <Border Grid.ZIndex="87" x:Name="ContentBorder" BorderBrush="White" Background="Crimson" CornerRadius="25">
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>                            
                        <Grid Grid.ZIndex="88"  x:Name="CellGridFocused"/>
                    </Grid>
                    <ControlTemplate.Triggers>

                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="Background" TargetName="CellGridFocused" Value="{DynamicResource Brush_DataGridCellFocused}" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" TargetName="CellContenGrind" Value="{DynamicResource Brush_DataGridSelected}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding ungelesen}" Value="0">
                <Setter Property="Background" Value="Green"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

我的 CellContentGrind 需要 Background="{TemplateBinding Background}" 因为一些其他的东西,所以我不能把它移到我的 Border.

如果 ungelesen = 0,我希望 ContentBorderBackground 为绿色。我该怎么做?

为什么不将样式移动到边框本身?

<Border Grid.ZIndex="87"x:Name="ContentBorder" BorderBrush="White" CornerRadius="25">
    <Border.Style>
        <Style TargetType="Border">
            <Setter Property="Background" Value="Crimson" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ungelesen}" Value="0">
                    <Setter Property="Background" Value="Green"/>
                </DataTrigger>
            </Style.Triggers>                 
        </Style>
    </Border.Style>

    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border> 

请注意,现在使用 Setter 设置背景,以便用 DataTrigger 覆盖。