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>
这篇关于是否在使用主题时更改按钮的默认背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:是否在使用主题时更改按钮的默认背景颜色?
基础教程推荐
猜你喜欢
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
