Windows phone 7 如何设置网格的背景?
我在玩样式,想设置网格的背景,比如:Windows phone 7 如何设置网格的背景?,windows-phone-7,xaml,Windows Phone 7,Xaml,我在玩样式,想设置网格的背景,比如: <Style TargetType="Grid"> <Setter Property="Background" Value="Background.png" /> </Style> 但这不起作用,正确的方法是什么。。。我怎么能像对待css中的类那样处理它,因为我希望它影响每个网格,即包装页面的网格?您可以像这样直接设置后台属性 <Grid x:Name="Co
<Style TargetType="Grid">
<Setter Property="Background" Value="Background.png" />
</Style>
但这不起作用,正确的方法是什么。。。我怎么能像对待css中的类那样处理它,因为我希望它影响每个网格,即包装页面的网格?您可以像这样直接设置后台属性
<Grid x:Name="ContentPanel" Style="{StaticResource GridStyle1}">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="/BackgroundImage.png"/>
</Grid.Background>
</Grid>
如果要创建样式资源,可以这样设置值
<phone:PhoneApplicationPage.Resources>
<Style x:Key="GridStyle1" TargetType="Grid">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/BackgroundImage.png" Stretch="Fill"/>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
<Grid Style="{StaticResource GridStyle1}"/>
我建议使用Expression Blend来帮助您了解如何使用样式。它将为您生成控件模板,以便您可以查看它们的结构。您可以像这样直接设置后台属性
<Grid x:Name="ContentPanel" Style="{StaticResource GridStyle1}">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="/BackgroundImage.png"/>
</Grid.Background>
</Grid>
如果要创建样式资源,可以这样设置值
<phone:PhoneApplicationPage.Resources>
<Style x:Key="GridStyle1" TargetType="Grid">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/BackgroundImage.png" Stretch="Fill"/>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
<Grid Style="{StaticResource GridStyle1}"/>
我建议使用Expression Blend来帮助您了解如何使用样式。它将为您生成控制模板,以便您可以查看它们的结构