样式中的悬停效果不起作用(工具栏面板) - WPF c#



我有一个我制作了自定义样式的工具栏。

<Window.Resources>
    <Style x:Key="toolbar_opciones" TargetType="{x:Type ToolBarPanel}">
        <Setter Property="Background" Value="DeepSkyBlue"/> <!-- does not work -->
        <Setter Property="Cursor" Value="Hand"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver"  Value="True">
                <Setter Property="Background" Value="CadetBlue"/>
            </Trigger> <!-- does not work -->
        </Style.Triggers>
    </Style>
</Window.Resources>
<ToolBarPanel Style="{StaticResource toolbar_opciones}"/>

光标有效,但是背景属性没有,为什么?

我测试了您的代码,这是修复

<ToolBarPanel Style="{StaticResource toolbar_opciones}"/>

仔细观察它,您缺少关闭Style属性的双引号。当我将其添加到XAML中时,已应用Background

欢呼。

最新更新