将背景图像添加到wp8应用程序

时间:2014-05-30 12:07:23

标签: c# xaml azure windows-phone-8

您好我试图将背景图片添加到我的一个项目页面中,我是xmal的新手,我需要一些帮助来理解为什么我在运行模拟器时无法看到背景。

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

enter image description here

3 个答案:

答案 0 :(得分:0)

看起来您正在使用计算机中的图像。请使用构建类型Content在项目中添加图像。然后将正确的路径指定为:

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

希望这会帮助。欢呼。

答案 1 :(得分:0)

检查构建操作是否设置为&#34; content&#34;。这可能导致了这个问题。 并检查您正在使用的图像的路径。它必须在你的项目中。理想情况下在assets文件夹中。或者在某个地方。 希望能帮助到你。欢呼声。

答案 2 :(得分:0)

不要添加您的PC地址。它不会在模拟器上运行。由于地址未解决。在Assets或解决方案中的任何文件夹中添加背景图像,然后使用

ImageSource = "Assets/background.png"

假设您在名为Assets

background.png文件夹中有图片
相关问题