无法在WP7中更改usercontrol的背景图像

时间:2012-05-29 04:53:15

标签: silverlight windows-phone-7 grid

我正在开发一个Windows Phone应用程序。我是WP7应用程序开发的新手。在我的应用程序中,我使用了一个用户控件,并通过我的代码中显示的以下过程更改了它的背景图像。但背景图像并没有改变。谁能帮我 ? 这是我的代码片段:

<Grid>
    <Image Source="\assests\backgroungimages\appBackground2.jpg" Stretch="UniformToFill"/>
    <StackPanel x:Name="LayoutRoot"  Width="480" Height="306" Background="Black">
        <TextBlock x:Name="ApplicationTitle" Text="Sign In" Style="{StaticResource PhoneTextNormalStyle}" Foreground="#CBF7FA" FontSize="30"/>
        <toolkit:PhoneTextBox Hint="UserName" Name="txtUsername" Width="auto" HintStyle="{StaticResource HintCustomStyle}"></toolkit:PhoneTextBox>
        <toolkit:PhoneTextBox Hint="Password" Name="txtPassword" Width="auto" HintStyle="{StaticResource HintCustomStyle}"></toolkit:PhoneTextBox>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Button Content="Sign In" Name="btnSignIn" Width="auto" Grid.Column="0" Grid.Row="0">
                <Button.Background>
                    <ImageBrush ImageSource="\assests\backgroungimages\btnImage.jpg" Stretch="UniformToFill"></ImageBrush>
                </Button.Background>
            </Button>
            <Button Content="Cancel" Name="btnCancel" Width="auto" Grid.Column="1" Grid.Row="0">
                <Button.Background>
                    <ImageBrush ImageSource="\assests\backgroungimages\btnImage.jpg" Stretch="UniformToFill"></ImageBrush>
                </Button.Background>
            </Button>
        </Grid>
    </StackPanel>
</Grid>

1 个答案:

答案 0 :(得分:1)

Set grid background to  

<Grid.Background>
   <ImageBrush ImageSource="\assests\backgroungimages\appBackground2.jpg"/>
</Grid.Background>