【发布时间】:2017-05-04 16:04:06
【问题描述】:
我怎样才能把一个适合自己的图像作为对象stackLayout的背景?
<ContentPage.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<StackLayout BackgroundColor="#FF1100" Grid.Row="0" Grid.Column="0" VerticalOptions="Fill" HorizontalOptions="Fill">
<Image Aspect="Fill" x:Name="backgroundImage"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"/>
</StackLayout>
<StackLayout BackgroundColor="#FF7700" Grid.Row="1" Grid.Column="0" VerticalOptions="Fill" HorizontalOptions="Fill">
<!--<Image Aspect="Fill" x:Name="backgroundImage"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"/>-->
</StackLayout>
</Grid>
【问题讨论】:
-
这段代码你看到了什么结果?你能分享你看到的截图并解释它是不是你想要的吗?注意* 这里的 RelativeLayout 约束无效,因为这是一个 StackLayout。
-
我希望结果是图像覆盖对象 stackLayout 的整个表面,无论长度或高度如何。这是可能的 ?图像不应明显撕裂。
标签: c# xamarin xamarin.forms portable-class-library