我开发了一个UWP应用程序,并使用了模板10. 我有一个黑色图像和一个白色图像。我想,当用户选择深色的主题,显示白色图像,当用户选择清淡的主题显示黑色图像,为例:根据应用程序主题显示图像
if(dark theme)
{
white image;
}
else
{
black image;
}
我开发了一个UWP应用程序,并使用了模板10. 我有一个黑色图像和一个白色图像。我想,当用户选择深色的主题,显示白色图像,当用户选择清淡的主题显示黑色图像,为例:根据应用程序主题显示图像
if(dark theme)
{
white image;
}
else
{
black image;
}
可以使用this.RequestedTheme
获取当前RequestedTheme然后将它与ElementTheme.Light
或ElementTheme.Dark
比较
方法1
if (this.RequestedTheme == ElementTheme.Light)
BackgroundImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/BlackImage.png"));
else
BackgroundImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/WhiteImage.png"));
方法2
BackgroundImage.Source = (this.RequestedTheme == ElementTheme.Light)? new BitmapImage(new Uri("ms-appx:///Assets/BlackImage.png")): new BitmapImage(new Uri("ms-appx:///Assets/WhiteImage.png"));
我不认为它的问题。我认为你可以阅读文档:https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/xaml-theme-resources – lindexi
是否[this](https://stackoverflow.com/a/44600513/7331395)答案有效? –