【发布时间】:2016-07-15 20:33:06
【问题描述】:
我想在鼠标悬停时将扩展器的背景颜色更改为较浅的变体。所以我想我使用触发器和转换器在鼠标悬停时将背景颜色转换为更亮的变体。我开始很简单,只实现了触发器。这行得通:
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type Expander}">
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Expander Header="Header">
<StackPanel>
<TextBox Background="Transparent">Content</TextBox>
</StackPanel>
</Expander>
</StackPanel>
所以我几乎可以实现我想要的。但我希望能够像这样在扩展器上设置颜色:
<Expander Header="Header" Background="Yellow">
在我添加颜色切换停止工作并且扩展器始终为黄色的那一刻。为什么会这样?我该如何实现我的目标?
编辑: 在我的最终应用程序中,我将拥有一个带有多个扩展器的 itemscontrol,其背景颜色数据绑定到我的视图模型,所以我认为我无法在样式中设置颜色。
<ItemsControl ItemsSource="{Binding TestStepDescriptions}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type localVMsTestEngines:AutomaticTestStepDescription}">
<Expander Background="{Binding StepStatus, Converter={StaticResource StepStatusToColorConverter}}">
问候, 杰夫
【问题讨论】: