我有一个包含图像和TextBlock的堆栈面板。
TextBlock绑定到一种样式,该样式使其闪烁,其背景颜色从红色变为黑色,反之亦然。
我想将TextBlock backgorund颜色绑定到stackpanel背景颜色,也就是说,当TextBlock背景颜色为Red时,我需要stackpanel背景颜色为Red,而当TextBlock背景颜色为Black时,stackpanel背景颜色必须更改为黑色等等...
在我的代码下面:
<Border Visibility="{Binding Path=BlinkOn, Converter={StaticResource BoolToVis}}" BorderThickness="1" BorderBrush="Red" CornerRadius="5" Margin="5">
<StackPanel Orientation="Horizontal" Width="auto" Background="Red">
<Image Width="24" Height="24" Source="/My.Images;component/Warning.png" />
<TextBlock x:Name="lblStoryboard"
TextAlignment="Center"
Padding="5"
Width="Auto"
Background="Red"
Foreground="Black"
FontSize="12.5"
FontWeight="Bold"
Style="{StaticResource BlinkingTextBlock}"
Text="Hi there!"
TextWrapping="WrapWithOverflow"
Visibility="{Binding Path=BlinkOn, Converter={StaticResource BoolToVis}}">
</TextBlock>
</StackPanel>
</Border>
答案 0 :(得分:-2)
我已经通过将TextBlock背景属性绑定到stackpanel背景属性来解决:
<Border Visibility="{Binding Path=BlinkOn, Converter={StaticResource BoolToVis}}" BorderThickness="1" BorderBrush="Red" CornerRadius="5" Margin="5">
<StackPanel Orientation="Horizontal" Width="auto">
<StackPanel.Background>
<Binding ElementName="txtStoryboard" Path="Background"/>
</StackPanel.Background>
<Image Width="24" Height="24" Source="/My.Images;component/Warning.png" />
<TextBlock x:Name="txtStoryboard"
TextAlignment="Center"
Padding="5"
Width="Auto"
Background="Red"
Foreground="Black"
FontSize="12.5"
FontWeight="Bold"
Style="{StaticResource BlinkingTextBlock}"
Text="Hi there!"
TextWrapping="WrapWithOverflow"
Visibility="{Binding Path=BlinkOn, Converter={StaticResource BoolToVis}}">
</TextBlock>
</StackPanel>
</Border>