【问题标题】:Change button color on hover UWP [duplicate]悬停UWP时更改按钮颜色[重复]
【发布时间】:2021-11-10 04:41:00
【问题描述】:

我想将按钮的背景颜色更改为红色,当悬停在它上面时,当不悬停在它上面时,它应该是白色的,我尝试使用 got focus 和 lost focus 但它们不起作用。请帮我 提前致谢!

【问题讨论】:

  • 回答了类似的问题here

标签: c# wpf windows xaml uwp


【解决方案1】:

悬停在下图中的按钮上时,您可以更改背景和前景。您可以根据深色和浅色主题的使用情况指定颜色。如果它只应用于一个按钮,这是有道理的。如果所有按钮的设计相同,则需要在 App.xaml 中覆盖它。

您可以找到更多详细信息here

<Button Background="Red" Foreground="Black" Content="BUTTON">
        <Button.Resources>
            <ResourceDictionary>
                <ResourceDictionary.ThemeDictionaries>
                    <ResourceDictionary x:Key="Dark">
                        <SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="Blue"/>
                        <SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="White"/>
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="Light">
                        <SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="Blue"/>
                        <SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="White"/>
                    </ResourceDictionary>
                </ResourceDictionary.ThemeDictionaries>
            </ResourceDictionary>
        </Button.Resources>
    </Button>

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 2014-09-09
    • 2021-08-27
    • 2017-07-21
    • 2019-09-07
    • 2012-08-16
    • 2016-05-26
    • 2019-10-19
    • 2021-09-18
    相关资源
    最近更新 更多