我正在尝试更改 app.xaml 中所有 xaml 页面的背景图片,但没有成功。
我正在 App 构造函数中尝试以下操作:
var imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/SomeBackgroundImage.png", UriKind.Relative))
};
RootFrame.Background = imageBrush;
我不想在页面级别执行此操作,因为所有页面都将具有相同的背景图片,具体取决于用户选择的主题。
关于我在这里做错了什么的想法?
最佳答案
我最终做了什么:
我创建了一个方法来根据所选主题选择正确的背景图像。
public static ImageBrush GetBackground()
{
var imageBrush = new ImageBrush();
if ((Visibility)App.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
{
imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/Background1.png", UriKind.Relative))
};
}
else
{
imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/Background2.png", UriKind.Relative))
};
}
return imageBrush;
}
并且在每个页面中我都设置了背景图片。
LayoutRoot.Background = Utils.GetBackground();
关于c# - Windows Phone 应用程序背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045848/