【发布时间】:2021-11-10 04:41:00
【问题描述】:
我想将按钮的背景颜色更改为红色,当悬停在它上面时,当不悬停在它上面时,它应该是白色的,我尝试使用 got focus 和 lost focus 但它们不起作用。请帮我 提前致谢!
【问题讨论】:
-
回答了类似的问题here
我想将按钮的背景颜色更改为红色,当悬停在它上面时,当不悬停在它上面时,它应该是白色的,我尝试使用 got focus 和 lost focus 但它们不起作用。请帮我 提前致谢!
【问题讨论】:
悬停在下图中的按钮上时,您可以更改背景和前景。您可以根据深色和浅色主题的使用情况指定颜色。如果它只应用于一个按钮,这是有道理的。如果所有按钮的设计相同,则需要在 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>
【讨论】: