Windows 10 UAP更改颜色主题

时间:2015-10-17 12:28:03

标签: c# windows xaml windows-phone-8.1

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

2 个答案:

答案 0 :(得分:1)

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

灯光主题示例:

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

/// <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中的

<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类的构造函数中:

替换

this.RequestedTheme = ApplicationTheme.Light;

this.RequestedTheme = ApplicationTheme.Dark;

在您的应用代码或

或XAML中的

RequestedTheme="Dark"

答案 1 :(得分:0)

使用RequestedThemeProperty。您可以从xaml或代码后面为每个页面,控件等更改它。

例如: xml.php