如何以编程方式更改我的应用程序的主题(例如,从黑暗到光明)?我想我可以重新定义系统资源。
发布于 2015-10-17 12:36:51
RequestedTheme Windows 8.1,您可以在任何控件上设置属性,甚至在应用程序级别设置为,以覆盖用户在设置中设置的主题。
轻型主题的示例:
在代码中,在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"发布于 2015-10-17 12:35:01
使用RequestedThemeProperty。您可以从xaml或后面的代码对每个页面、控件等进行更改。
例如:RequestedTheme="Light"
https://stackoverflow.com/questions/33186615
复制相似问题