如何设置ComboBox已经选中项的背景色。(C#)
-
2012年5月10日 2:41
如下图,这是一个ComboBox. 我之前已经选中了Item3,但是Item3的背景色是青色的,我想把它改成红色,请问如何Code。
有人可以提供Code Sample嘛,谢谢!
全部回复
-
2012年5月10日 9:39版主
用Blend去修改设计。
在Blend中新建一个XAML项目,随意放置一个ComboBox,然后如下图:
导出其ComboBox的ComboBoxItem的默认样式,找到下面一段:
<VisualState x:Name="Selected"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerGrid"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemHighlightFillBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> <DiscreteObjectKeyFrame KeyTime="0" Value="White"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState>将 <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemHighlightFillBrush}"/> 中的Value修改至你需要的颜色,比如Red。
然后你就可以将整个style复制到你的项目中,如此应用:
<ComboBox ItemContainerStyle="{StaticResource ComboBoxItemStyle1}"/>Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 Water Cube 2012年5月14日 1:52


