我是一个图形设计师谁是WPF和XAML的新手。我想创建一个ComboBox,其中选定的项保持选中状态,直到选择了一个新项。同时,当用户想要将鼠标移到其他项目上时,我希望为突出显示显示不同的颜色。我使用的是blend和c#。
如果这有点令人困惑,我做了一个简单的说明。谢谢!!
这是我的图片的链接:http://www.flickr.com/photos/jeddahbalgame/6633558209/
发布于 2012-01-04 11:27:18
您可以使用触发器来指定选中项目时项目应为何种颜色
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="White" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>要更改鼠标所在项目的颜色,实际上必须覆盖ComboBox的HighlightBrush,因为它是系统颜色。你也可以在你的风格中做到这一点
<Style TargetType="{x:Type ComboBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow"/>
</Style.Resources>
<Setter Property="Background" Value="White" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>https://stackoverflow.com/questions/8720308
复制相似问题