ContentViewは、コントロールを1つだけ配置することができるコントロールです。
配置したコントロールはContentViewのサイズと同じになります。ContentViewはサイズに変更があった場合にはSizeChangedイベントが発生します。
以下は、Gridを配置して1行目にStackLayoutを、2行目にContentViewを配置する例です。
2行目はContentViewの高さを200に設定しているのですが、内側に配置したLabelの高さはContentViewの高さに合わせて広がります。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ContentViewSample"
x:Class="ContentViewSample.MainPage">
<Grid Margin="10,30,10,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Orientation="Horizontal" Grid.Row="0">
<Label x:Name="lblContent1" Text="Hello Xamarin!" BackgroundColor="Lime" />
</StackLayout>
<ContentView Grid.Row="1"
x:Name="contentView" Padding="10,30,10,10"
HeightRequest="200">
<Label x:Name="lblContent2" Text="Hello Xamarin!" BackgroundColor="Aqua" />
</ContentView>
</Grid>
</ContentPage>
実行例を以下に示します。
Please follow and like us:


コメント