简体   繁体   中英

How to set background image in Windows Phone 8?

I am very new to WP apps and don't know how to set the back-ground image in app.xaml file for whole application in Windows Phone 8 app. Up-till now, i have placed some controls over it but fail to set background image. I have seen some material but did not work. Any help will be appreciated !

You can add a Common Grid Style which uses Image as background.And place it under App.xaml.Resources.

<Application.Resources>
    <Style x:Key="LayoutGridStyle" TargetType="Grid">
          <Setter Property="Background">
            <Setter.Value>
                <ImageBrush ImageSource="/Assets/bgImage.jpg"/>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>

And use it for the Root grid of your page.

<Grid x:Name="LayoutRoot"  Style="{StaticResource LayoutGridStyle}">
//Content goes here
</Grid>

I use the following in the InitializePhoneApplication method of my app.xaml.cs. The effect is that every page has the same background image, and there's no flashing/blanking upon page navigation

 RootFrame = new PhoneApplicationFrame
 {
    Background = new ImageBrush()
    {
       ImageSource = new BitmapImage(new Uri("Assets/Russel_Logo_ep2s.png", UriKind.Relative)),
       Opacity = 0.3,
       Stretch = System.Windows.Media.Stretch.None,
       AlignmentX = AlignmentX.Center,
       AlignmentY = AlignmentY.Center
    }
 };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM