Style.DataTrigger on Border background
Asked Answered
M

1

29

I have the border below. Why would the Foreground of my TextBlock work correctly but the Background of the border always stay the same (as if the IsDeleted property is always false)

<Border DockPanel.Dock="Top" BorderBrush="Black" Background="#CBE2FF" BorderThickness="2" CornerRadius="5" Padding="0" Margin="5">
    <Border.Style>
        <Style TargetType="{x:Type Border}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsDeleted}" Value="True">
                    <Setter Property="Background" Value="#A00000"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
    <TextBlock Margin="5" FontWeight="Bold" FontSize="14" Text="Queue Details">
        <TextBlock.Style>
            <Style TargetType="{x:Type TextBlock}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsDeleted}" Value="True">
                        <Setter Property="Foreground" Value="White"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
</Border>
Milomilon answered 30/7, 2010 at 17:16 Comment(0)
S
50

You have explicitely set the background value on the border. This has more priority than the trigger. Remove the Background="#CBE2FF" and take it into the style.

<Border.Style>
   <Style TargetType="{x:Type Border}">
      <Setter Property="Background" Value="#CBE2FF"/>
      ...

This will help.

Schaumberger answered 30/7, 2010 at 17:22 Comment(1)
perfect. i didn't know if i set it in the property it over-rode that. thanksMilomilon

© 2022 - 2024 — McMap. All rights reserved.