简体   繁体   中英

Add background image to wp8 app

Hello i tried to add background image to one of my project pages , I am new to xmal and i need some help to understand why i cant see the background when i run the emulator.

<phone:PhoneApplicationPage
    x:Class="ipublicSrv.Pages.MusicMenuPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.Background>
            <ImageBrush ImageSource="C:\Users\lior\Documents\Visual Studio 2013\Projects\IPubProject\ipublicSrv\ipublicSrv\Resources\24796-armin-van-buuren.jpg"
                    Stretch="UniformToFill" />
        </Grid.Background>
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="Music Menu" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

在此处输入图片说明

Looks like you are using Image from Your Computer.Please add image in your project with Build type Content .then give correct path as :

ImageSource="/Resources/Images/yourImage.png //if you added image in `Resource/Image` folder.

Hope this Helps.Cheers.

Check if the build action is set to "content". That might be causing the issue. And also check the path of the image that you are using. It has to be inside your project. Ideally inside the assets folder. or somewhere separately. Hope it helps. Cheers.

Don't add your PC address. It won't run on emulator. Since the address isn't resolved. Add the background image in the Assets or any folder in your solution then use

ImageSource = "Assets/background.png"

Assuming you have image in Assets folder named background.png

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