Error in changing the background dynamically

谁说胖子不能爱 提交于 2019-12-31 04:55:30

问题


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
            }
        }
    }

回答1:


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)



来源:https://stackoverflow.com/questions/10483812/error-in-changing-the-background-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!