Dan*_*nte 3 c# windows-phone-7
我正在尝试更改app.xaml中所有xaml页面的背景图像,但未成功.
我在App构造函数中尝试以下操作:
var imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/SomeBackgroundImage.png", UriKind.Relative))
};
RootFrame.Background = imageBrush;
Run Code Online (Sandbox Code Playgroud)
我不想在页面级别执行此操作,因为所有页面将具有相同的背景图像,具体取决于用户选择的主题.
关于我在这里做错了什么的想法?
Dan*_*nte 10
我最终做了什么:
我根据所选主题创建了一个选择正确背景图像的方法.
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;
}
Run Code Online (Sandbox Code Playgroud)
在每个页面中,我设置了背景图像.
LayoutRoot.Background = Utils.GetBackground();
Run Code Online (Sandbox Code Playgroud)