Windows 10个UAP换色主题
Windows 10 UAP change color theme
如何以编程方式更改我的应用程序的主题(例如从深色到浅色)?我想我可以重新定义系统资源。
使用RequestedThemeProperty。您可以将其更改为 xaml 或每个页面、控件等的代码隐藏
例如:
RequestedTheme="Light"
WindowsPhone8.1,你可以在任何控件上设置RequestedTheme属性,甚至在应用级别覆盖用户在设置中设置的主题。
浅色主题示例:
在代码中,在 App 的构造函数中 class :
/// <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 的构造函数中 class :
替换
this.RequestedTheme = ApplicationTheme.Light;
和
this.RequestedTheme = ApplicationTheme.Dark;
在您的应用程序代码中或
或在XAML中:
RequestedTheme="Dark"
如何以编程方式更改我的应用程序的主题(例如从深色到浅色)?我想我可以重新定义系统资源。
使用RequestedThemeProperty。您可以将其更改为 xaml 或每个页面、控件等的代码隐藏
例如:
RequestedTheme="Light"
WindowsPhone8.1,你可以在任何控件上设置RequestedTheme属性,甚至在应用级别覆盖用户在设置中设置的主题。
浅色主题示例:
在代码中,在 App 的构造函数中 class :
/// <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 的构造函数中 class :
替换
this.RequestedTheme = ApplicationTheme.Light;
和
this.RequestedTheme = ApplicationTheme.Dark;
在您的应用程序代码中或
或在XAML中:
RequestedTheme="Dark"