【发布时间】:2017-06-23 14:17:17
【问题描述】:
我正在开发一个 UWP 应用,我正在使用 template10。我有两张图片,一张是白色的,另一张是黑色的。我想在浅色主题中显示黑色图像,在深色主题中显示白色图像。我有这个代码:
if (this.RequestedTheme == ElementTheme.Light)
Image.Source = new BitmapImage(new Uri("ms-appx:///Assets/BlackImage.png"));
else
Image.Source = new BitmapImage(new Uri("ms-appx:///Assets/WhiteImage.png"));
但是,当我选择浅色主题图像时不会出现!但是当我选择深色主题时,会出现白色图像。
【问题讨论】:
-
确保此代码有效,因为我已在我的应用程序中使用它。另外,如果您对此代码有任何问题,请在this 答案上发表评论。不要创建新帖子说答案无效。
-
确保资产确实在您期望的位置,您确认黑色图像在那里吗?
-
什么是
this?是Application吗?还是Page?你也在Initialization中使用它吗?或Button点击?