首先,我创建了一个按钮(名为BackgroundChooser),用于动态更改背景图像(他们可以选择自己的图像作为背景)。但我已经为我的windows phone7应用程序使用了默认的背景图片(image1.jpg)。当我点击“选择背景”按钮时,它会指向我们保存的图片。在那之后,我选择了am image作为我自己的背景图像。但是默认的背景图像仍然没有改变。然后,当我将默认背景更改为黑色时,我可以设置我自己的背景图像(它工作得很好)。需要帮助!提前感谢您的辛勤工作!
下面是我使用的代码:
private void BackgroundChooser_Click(object sender, MouseEventArgs e)
{
var PhotoChooser = new PhotoChooserTask();
PhotoChooser.Completed += new EventHandler<PhotoResult(PhotoChooser_Completed);
PhotoChooser.Show();
}
void PhotoChooser_Completed(object sender, PhotoResult e)
{
{
if (e.TaskResult == TaskResult.OK)
{
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
var app = Application.Current as App;
if (app == null)
return;
var imageBrush = new ImageBrush { ImageSource = bmp, Opacity = 0.5d };
app.RootFrame.Background = imageBrush;
//app.RootFrame.Background = new SolidColorBrush(Colors.Black); //we can apply just color too like this
}
}
}发布于 2012-05-08 07:52:19
而不是 app.RootFrame.Background,尝试在页面上的一些显示对象(如myPanoramaControl.Background = imageBrush;或LayoutRoot.Background = imageBrush;,其中LayoutRoot是新WP页面的默认网格控件的名称)上设置背景属性,而不是设置背景属性
https://stackoverflow.com/questions/10483812
复制相似问题