Change default background color of buttons while using a theme?(是否在使用主题时更改按钮的默认背景颜色?)
本文介绍了是否在使用主题时更改按钮的默认背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网格中有以下资源XML:
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/classic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
这是有效的,我加载了经典主题。但是经典的主题按钮背景是非常白的吗?是否可以更改此主题中按钮的默认背景颜色?
推荐答案
您可以使用样式仅将背景颜色设置为其他颜色。
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Background" Value="Green" />
</Style>
这里的关键是使用BasedOn="{StaticResource {x:Type Button}}"
,因为这将确保按钮基于当前的style/theme
。在本例中,这将是Classic
。如果我们没有赋值,它将简单地将其基于原始主题,即Aero
。
我通常有一个XAML文件,我在其中存储所有自定义主题数据并加载它
<ResourceDictionary Source="ThemesMyTheme.xaml"/>
在这种情况下,它将包含以下内容
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Background" Value="Green" />
</Style>
</ResourceDictionary>
这篇关于是否在使用主题时更改按钮的默认背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:是否在使用主题时更改按钮的默认背景颜色?


猜你喜欢
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01