首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows 10 UAP更改颜色主题

Windows 10 UAP更改颜色主题
EN

Stack Overflow用户
提问于 2015-10-17 12:28:03
回答 2查看 534关注 0票数 1

如何以编程方式更改我的应用程序的主题(例如,从黑暗到光明)?我想我可以重新定义系统资源。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-17 12:36:51

RequestedTheme Windows 8.1,您可以在任何控件上设置属性,甚至在应用程序级别设置为,以覆盖用户在设置中设置的主题。

轻型主题的示例:

在代码中,在App类的构造函数中:

代码语言:javascript
复制
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public sealed partial class App : Application
{
    private TransitionCollection transitions;

    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
    public App()
    {
        this.RequestedTheme = ApplicationTheme.Light;

        this.InitializeComponent();
        this.Suspending += this.OnSuspending;
    }
}

或在XAML中:

代码语言:javascript
复制
<Application
    x:Class="App26.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    RequestedTheme="Light"
    xmlns:local="using:App26">
</Application>

黑暗主题

在代码中,在App类的构造函数中:

替换

代码语言:javascript
复制
this.RequestedTheme = ApplicationTheme.Light;

使用

代码语言:javascript
复制
this.RequestedTheme = ApplicationTheme.Dark;

在你的应用程式码或

或在XAML中:

代码语言:javascript
复制
RequestedTheme="Dark"
票数 1
EN

Stack Overflow用户

发布于 2015-10-17 12:35:01

使用RequestedThemeProperty。您可以从xaml或后面的代码对每个页面、控件等进行更改。

例如:RequestedTheme="Light"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33186615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档