通常我将标签与文本框/组合框一对一地关联起来,这样我就可以在组合框有焦点时装饰标签......像这样
<Label
Grid.Row="1"
Grid.Column="1"
Style="{StaticResource styleLabelTextBlockLeft}"
Tag="{Binding ElementName=cboColor, Path=(IsFocused)}"
>
<TextBlock
TextWrapping="Wrap">What is your favorite color?
</TextBlock>
</Label>
<ComboBox
x:Name="cboColor"
Grid.Row="1"
Grid.Column="3"
...
/>
如果标签右侧的 ComboBox 具有焦点或第一个 ComboBox 右侧的第二个 ComboBox 具有焦点(都在同一行),我想做的是突出显示标签。伪代码如下:
<Label
Grid.Row="1"
Grid.Column="1"
Style="{StaticResource styleLabelTextBlockLeft}"
Tag="{Binding ElementName=cboColorOne, Path=(IsFocused)}"
Tag="{Binding ElementName=cboColorTwo, Path=(IsFocused)}"
>
<TextBlock
TextWrapping="Wrap">What is your favorite color?
</TextBlock>
</Label>
<ComboBox
x:Name="cboColorOne"
Grid.Row="1"
Grid.Column="3"
...
/>
<ComboBox
x:Name="cboColorTwo"
Grid.Row="1"
Grid.Column="5"
...
/>
有任何想法吗?谢谢。