【问题标题】:Windows 10 UAP change color themeWindows 10 UAP 更改颜色主题
【发布时间】:2016-01-16 03:49:04
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    Light 主题示例:

    在代码中,在 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"
    

    【讨论】:

      【解决方案2】:

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

      例如: RequestedTheme="Light"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-10
        • 1970-01-01
        • 2016-04-14
        相关资源
        最近更新 更多