Apply background image in windows phone 7 application
In this post I am going show how we can apply an image in your app background. This we can do in XAML and also using C# code.
Video :-
[youtube=http://www.youtube.com/watch?v=FfJqEK4kEzY]
If we want to set image using XAML, it is easy. Just we need to set background for top parent element, in my Demo Grid (default) is top parent element. So, I am applying background image to that.
Just add the below code after <Grid> tag
<ImageBrush ImageSource=”images/bg.png” Stretch=”UniformToFill” />
</Grid.Background>
C#.net Code:-
Some time we need to change the background using your code. For example if the user selected one movie we need set that film image we need to show in background.
In my example I am use PhotoChooserTask user to select his image for background.
For this we need to do flowing things
*Note: – Please not apply background for grid
// create the PhotoChooserTask object with page scope.
PhotoChooserTask photoChooserTask;
Then
Then in Constructor just add the below highlighted code
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
In button click event I am just showing PhotoChooserTask
{
photoChooserTask.Show();
}
In photoChooserTask_Completed event
{
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.Blue); — we can apply just color too like this
}
}
I hope, it will be helpful for beginners!!!!!
Enjoy while coding..!
Thanks,
Naga Harish.
Can I change a similary wallpaper in Windows Phone 7 ?
Hi Marcin,
I am sorry, because I am not clear with you question first. Can you please tell me in detail. So, may be I can help you..! 🙂 Anyway thanks for visiting my blog 🙂
I would like to change system wallpaper Windows Phone 7 in c# code.
Oh!, you want to change home screen background of your WP7? I hope with this SDK we can’t do that!
Hi I need to set a wallpaper in my windows phone… It should appear behind the tiles. Can you guide me how to do it?
If I understand you comment correct. It is not possible to set bg for homescreen (Bg behuind tiles).
Are U sure about this thing..i mean is there no app tht can do this thing ??
Yes @utkarsh, up to my knowledge there is no app or setting to change home screen background (only black or white).
We can change lock screen image.. there are some many app for that.. for example Facebook and Twitter..