I want to synchronize the background of two TextBlockes. For example, if the mouse is over any of the textblockes, I’d like to change the background color to the same for both textblockes. I know I can use this trigger to change one background:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="LightGray"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
But how to sync them?
UPDATE: this is not working either:
<UserControl.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="LightGray"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Background="{Binding Path=Background, ElementName=tbHeader, Mode=TwoWay}" Text="A"/>
<TextBlock x:Name="tbHeader" Grid.Column="1" Text="B"/>
</Grid>
You can sync it by placing them in
ContentControland applying trigger onControlTemplatelike this –