错误动态变化的背景 [英] Error in changing the background dynamically
问题描述
首先,我已经创建了用于动态更改背景图片(他们可以选择自己的图片作为背景)按钮(命名为BackgroundChooser)。但我已经使用了默认的背景图像(image1.jpg)为我的Windows Phone 7应用程序。当我在选择背景按钮点击,它引导我们保存的图片。从那以后,我选择了上午的图像作为我自己的背景图像。但是默认背景图像仍然不改变。
然后当我改变了默认背景为黑色,然后我可以将我自己的背景图像(它的工作完美)。需要帮助!!!预先感谢你们的辛勤工作!
First i've created a button(named as BackgroundChooser) that is used to change the background image dynamically(they can select their own image as background). But i have already used a default background image(image1.jpg) for my windows phone 7 application. When i click on the choose background button, it directs to our saved pictures. After that i have selected am image as my own background image. But the default background image is still doesn't changed. Then when i have changed the default background to black, then i can set my own background image(it's working perfectly). Need help!!! Thanks in advance for your hard work!!!
下面是我所使用的代码 -
Below is the code i have used-:
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
}
}
}
推荐答案
而不是 app.RootFrame.Background
,可以尝试设置一些显示对象的背景属性您的网页上,如 myPanoramaControl.Background =的ImageBrush;
或 LayoutRoot.Background =的ImageBrush;
(其中LayoutRoot是默认网格控件的名称一个新的WP页)
instead of app.RootFrame.Background
, try setting the Background property on some display object on your page such as myPanoramaControl.Background = imageBrush;
or LayoutRoot.Background = imageBrush;
(where LayoutRoot is the name of the default grid control for a new WP Page)
这篇关于错误动态变化的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!