wpf - 为什么我的 IsMouseOver 风格在我的 Controller 风格中什么都不做

标签 wpf mahapps.metro

所以我有这个样式:

xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"

<Style TargetType="Controls:NumericUpDown">
    <Setter Property="Background" Value="#FF307AE4"/>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Background" Value="Gray"/>
            <Setter Property="BorderBrush" Value="Gray"/>
        </Trigger>

        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="BorderBrush" Value="Gainsboro"/>
        </Trigger>

        <Trigger Property="IsMouseOver" Value="False">
            <Setter Property="BorderBrush" Value="Gray"/>
        </Trigger>
    </Style.Triggers>
</Style>

我定义了几种颜色并想要更改 IsMouseOver 属性,但似乎这根本没有效果。

IsEnabled 工作正常。

我做错了什么?

最佳答案

看看您是否还在控件中设置了 BorderBrush 属性,认为它会设置一些初始值。这将始终优先于通过您的样式所做的任何更改。

我尝试过以下代码:

<Controls:NumericUpDown Minimum = "0" Maximum = "10000" Interval = "5" StringFormat="C2" Padding="5">
            <Controls:NumericUpDown.Style>
                <Style TargetType="Controls:NumericUpDown">
                <Setter Property="Background" Value="Pink"/>
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="True">
                        <Setter Property="Background" Value="Yellow"/>
                    </Trigger>                  

                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="Background" Value="DeepSkyBlue"/>
                            <Setter Property="BorderBrush" Value="Black"/>
                            <Setter Property="BorderThickness" Value="3"/>
                        </Trigger>

                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="Cornsilk"/>
                            <Setter Property="BorderBrush" Value="Purple"/>
                            <Setter Property="BorderThickness" Value="3"/>
                        </Trigger>

                    </Style.Triggers>
            </Style>
            </Controls:NumericUpDown.Style>
        </Controls:NumericUpDown>

和鼠标悬停边框效果根本不可见。背景工作正常,但 BorderBrush、BorderThickness 根本不起作用。这肯定是一个错误。

但是当我们应用本页给出的某种样式时,情况就会发生变化。但 borderbrush 仍然没有改变。但 BorderThickness 工作正常。你可以尝试一下。一旦熟悉了这一点,我就会更新更多内容。

http://mahapps.com/guides/styles.html#app

关于wpf - 为什么我的 IsMouseOver 风格在我的 Controller 风格中什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33186952/

相关文章:

wpf - 在 Canvas 上获取鼠标位置(但不在窗口上)?

c# - 将样式与 HierarchicalDataTemplate 与 Caliburn.Micro 和 MahApps 框架一起使用

c# - MahApps Metro 和 DataGridExtensions

wpf - 仅在非常特殊的情况下,Visual Studio Intellisense不能在XAML上运行

c# - 在更改的回调中设置 DependencyProperty 值

c# - 如何在单击事件中设置 Canvas ZIndex WPF 按钮控件?

WPF - 当 ListView 为空时不显示上下文菜单

WPF 切换开关 : how to add Win 10 style

c# - 使用 MahApps 保持样式扩展 WPF 中的 TextBox

c# - WPF:如何更改 TransitioningContentControl 背景颜色?