UWP将资源替代转换为样式

问题描述 投票:0回答:1

我有使用自定义颜色的按钮:

<Button>
<Button.Resources>
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="Transparent" />
</Button.Resources>
</Button>

我想将其移至样式,因此我可以在按钮上设置样式,而不必将其放在按钮xaml中。我发现的唯一方法是重写按钮模板,这是荒谬的XAML更改一种颜色。有没有简单的方法可以做到这一点?

c# uwp uwp-xaml
1个回答
0
投票
UWP将资源替代转换为样式

ButtonBackgroundPointerOver纯色画笔,用于将按钮指针设置为状态颜色,但它不是按钮属性,因此我们不能像设置按钮背景属性那样进行设置,如果要实现特定按钮,更好的方法是创建自定义按钮,例如replay,如果要对页面上的整个按钮生效,可以在页面资源中定义它

<Page.Resources> <SolidColorBrush x:Key="ButtonForeground" Color="#FFFFFF"/> <SolidColorBrush x:Key="ButtonBackground" Color="#212121"/> <SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="#FFFFFF"/> <SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#424242"/> <SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="#FFFFFF"/> <SolidColorBrush x:Key="ButtonForegroundPressed" Color="#FFFFFF"/> <SolidColorBrush x:Key="ButtonBackgroundPressed" Color="#070707"/> </Page.Resources>

© www.soinside.com 2019 - 2024. All rights reserved.