更改Windows 10商店应用程序的主题颜色
本文关键字:颜色 应用程序 Windows 更改 | 更新日期: 2023-09-27 18:16:38
//这是app . xml .cs
中的代码private void DetermineAppTheme()
{
bool value = true;
if (ApplicationData.Current.LocalSettings.Values.ContainsKey("IsLightTheme"))
{
value = ((bool)ApplicationData.Current.LocalSettings.Values["IsLightTheme"]);
}
if (value == true)
{
this.RequestedTheme = (ApplicationTheme)ElementTheme.Light;
}
else
{
this.RequestedTheme = (ApplicationTheme)ElementTheme.Dark;
}
}
这是我以前在Windows 8/8.1商店应用程序中用来改变颜色的代码,但不幸的是,这在Windows 10应用程序上不起作用。
在我的设置页面中,我正在使用以下代码行更改单击主题的状态
ApplicationData.Current.LocalSettings.Values["IsLightTheme"] = false;
MessageDialog messageDialog = new MessageDialog("Please restart the Application so that Theme change can take place");
await messageDialog.ShowAsync();
为什么这不是改变颜色从白色到黑色,我不明白。如果在Windows 8应用程序上实现,则可以正常工作。
我的猜测是,在你的App.xaml.cs文件中,你正在设置value = true;然后if(value) {//set light theme}
如果value为false,则需要设置light theme
我自己找到了解决办法。首先
this.RequestedTheme = (ApplicationTheme)ElementTheme.Light;
必须改为
this.RequestedTheme = (ApplicationTheme)ElementTheme.Default;
和在app.xaml请求的主题必须被删除。然后这段代码会改变主题/