How to add a background image to Windows Phone Panorama App

2.4k Views Asked by At

I'm trying to add a background image to my Windows phone panorama application. When I add the image with XAML code, image can be seen in the preview. But when I run the app, I can't see the image. Size of the image I used 1536x1280

here is the XAML code I used;

<phone:Panorama.Background>
     <ImageBrush ImageSource="/Assets/back.png"/>
</phone:Panorama.Background>

Also I tried the following C# code;

        BitmapImage bitmapImage = new BitmapImage(new Uri("/Assets/back.png", UriKind.Relative));
        ImageBrush imageBrush = new ImageBrush();
        imageBrush.ImageSource = bitmapImage;
        this.Background = imageBrush;

how I see in the visual studio preview how I see in the visual studio preview

how I see in the emulator and the device how I see in the emulator and the device

2

There are 2 best solutions below

0
Chris Shao On BEST ANSWER

Check the 'Build Action' of your Image file. (In your solution, right click on your image file, and look at it's properties).

If the 'Build Action' is 'Content', your code is right.

But if the 'Build Action' is 'Resources', you should modify the image path to: 'ms-appx:///Assets/back.png'

0
Amir Jobs On

I solved this same problem by doing these things:

  • First in "Project" part of Visual Studio select "Add Exiting item"
  • Select your image.

Remember to address your image correctly.