我開發了一個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)答案有效? –