根据应用主题显示图像 [英] Display image depending on application theme

查看:96
本文介绍了根据应用主题显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发UWP应用,并且我正在使用模板10. 我有黑色图像和白色图像.我想当用户选择深色主题时显示白色图像,而当用户选择浅色主题时显示黑色图像,例如:

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;
}

推荐答案

您可以使用this.RequestedTheme获取当前的RequestedTheme,然后将其与ElementTheme.LightElementTheme.Dark

You can get current RequestedTheme using this.RequestedTheme and then compare it with ElementTheme.Light or 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"));

这篇关于根据应用主题显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆