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>
这篇关于是否在使用主题时更改按钮的默认背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:是否在使用主题时更改按钮的默认背景颜色?
 
				
         
 
            
        基础教程推荐
             猜你喜欢
        
	     - 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				