在Windows应用商店应用中添加背景图像

时间:2014-05-19 09:35:47

标签: c# xaml background windows-store-apps

最近我开始在XAML和C#中制作Windows应用商店应用。不幸的是,我添加了存储在'/ Assets'中的背景png图像失败了。到处寻找任何胶水,但我找不到任何有用的东西。

这是我的代码:

<Page
    x:Class="BoggleV01.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BoggleV01"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Margin="160,100" Width="1040">
        <Grid.Background>
            <ImageBrush ImageSource="/Assets/Background.png" Stretch="UniformToFill" />                                            
        </Grid.Background>

        <StackPanel x:Name="levelsStackPanel"  HorizontalAlignment="Left" Height="568" VerticalAlignment="Top" Width="260"/>
        <StackPanel x:Name="playersStackPanel" HorizontalAlignment="Left" Height="568" VerticalAlignment="Top" Width="260" Margin="260,0,0,0"/>
        <StackPanel x:Name="statisticsStackPanel" HorizontalAlignment="Left" Height="568" VerticalAlignment="Top" Width="260" Margin="520,0,0,0"/>
        <StackPanel x:Name="settingsStackPanel" HorizontalAlignment="Left" Height="568" VerticalAlignment="Top" Width="260" Margin="780,0,0,0"/>
    </Grid>
</Page>

1 个答案:

答案 0 :(得分:1)

您可以使用下面提到的代码

<ImageBrush ImageSource="/Applicationname;component/Assets/Background.png"
            Stretch="UniformToFill" />