嗨,我想用wpf创建一个平面组合框 . 实际上我已经完成了它但是当鼠标悬停在组合框上时它返回到它的旧样式 .
我有这个xaml代码:
<Style TargetType="ComboBox" x:Key="Flat_ComboBox">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="MinWidth" Value="60"/>
<Setter Property="UIElement.SnapsToDevicePixels" Value="True"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
<Setter Property="TextElement.Foreground" Value="Black"/>
<Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="White" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightSkyBlue" />
</Trigger>
</Style.Triggers>
</Style>
我需要更改Trigger“IsMouseOver”的哪些属性?
2 回答
您需要覆盖
ComboBox
的ControlTemplate
. voddy在评论中提到的链接将引导您(通过另一个链接)到默认的ComboBox
样式(http://msdn.microsoft.com/en-us/library/ms752094.aspx),您应该能够调整它以获得您想要的外观 .作为替代方案,您可以尝试使用Kaxaml(一个简洁的XAML工具)中包含的
ControlTemplate
,它已经具有更多"flat"外观 .供参考(来自Kaxaml):
会产生这样的东西:
您可能希望将模板分成
ResourceDictionary
,因此您可以在多个位置使用它 .您可能还想更改该行:
要使用命名键,您可以将其应用于特定的
ComboBox
元素:为什么这么复杂? ;)