Search code examples
c#xamlbackgroundwindows-phone-8.1panorama-control

How to add a background image to Windows Phone Panorama App


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


Solution

  • 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'