2016-12-19 18 views
2

オブジェクトスタックの背景として自分自身を適応させる方法を教えてください.Layout?stacklayout xamarinフォームに画像を塗りつぶす方法pcl

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

+0

このコードではどのような結果が表示されますか?あなたが見たもののスクリーンショットを共有し、あなたが望むものではないことを説明できますか?注:ここでのRelativeLayout制約は、これがStackLayoutであるため有効ではありません。 – therealjohn

+0

長さや高さにかかわらず、画像がオブジェクトstackLayoutの全面をカバーするようになったのが結果です。それが可能だ ?画像がはっきりと裂けてはならない。 –

答えて

0

私はあなたの最善の策は、RelativeLayoutを使用して、画像やStackLayoutを追加することだと思います。画像を最初に追加すると、背景にあります。例:

<RelativeLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="Silver"> 
    <Image 
     Source="MyImage.png" 
     Aspect="Fill" <!-- Stretches the image to fill, use AspectFill instead of Fill to enlarge the image without stretching the image --> 
     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
     RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}" 
     RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}" 
     RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" 
     /> 
    <StackLayout 
     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
     RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}" 
     RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}" 
     RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" > 
     <Label 
      Text="Image Stack Layout in Relative Layout" 
      TextColor="Lime" /> 
     <Button 
      Text="I'm a button" 
      TextColor="Lime" /> 
    </StackLayout> 
</RelativeLayout> 
+0

はこの解決策では自動的には適応しませんが、灰色の境界線は表示されません。画像を表面に合わせることは可能ですか? –

+0

イメージの 'Aspect'プロパティを' AspectFill'または 'Fill'に設定したいと思うでしょう。 'Fill'は画像を拡大表示してアスペクト比を変更し、AspectFillは画像を拡大して余白を切り取ります。私は私の答えを更新します。 – jgoldberger

関連する問題