问题
I am develop an UWP app, and I am using Template 10. I have a black image and a white image. I want when the user choose dark theme, show the white image, and when the user choose light theme show the black image, exemple:
if(dark theme)
{
white image;
}
else
{
black image;
}
回答1:
You can get current RequestedTheme using this.RequestedTheme
and then compare it with ElementTheme.Light
or ElementTheme.Dark
Method 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"));
Method 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://stackoverflow.com/questions/44599012/display-image-depending-on-application-theme