I want to change the Background property of a TextBlock if the Text is 00:00.Is there a simple, XAML solution? I've tried creating a DataTrigger but it's not changing the colour
<Style TargetType="TextBlock" x:Key="textBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding}" Value="00:00">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
<TextBlock Text="{Binding}" Margin="3" Style="{DynamicResource textBlock}"/>
What about a normal Trigger
?:
<Style TargetType="TextBlock" x:Key="textBlock">
<Style.Triggers>
<Trigger Property="TextBlock.Text" Value="00:00">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
I think your binding in your datatrigger should be
Binding="{Binding RelativeSource={RelativeSource Self},Path=Text}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With