Windows 10 UAP更改颜色主题
本文关键字:颜色 UAP Windows | 更新日期: 2023-09-27 18:18:03
如何以编程方式更改应用程序的主题(例如从Dark到Light) ?我想我可以重新定义系统资源。
Windows Phone 8.1,您可以在任何控件上设置 requestdtheme 属性,甚至在应用程序级别覆盖用户在设置中设置的主题。
光的示例主题:
在代码中,在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>
For Dark Theme
在代码中,在App类的构造函数中:代替
this.RequestedTheme = ApplicationTheme.Light;
this.RequestedTheme = ApplicationTheme.Dark;
在你的应用程序代码或
或在XAML:
RequestedTheme="Dark"
使用requestdthemeproperty。你可以改变它从xaml或代码后面的每个页面,控件等。
例如:RequestedTheme="Light"