问题
For now, I tried with below code
<StackLayout>
<StackLayout.Grid.Row>
<OnPlatform ... />
</StackLayout.Grid.Row>
</StackLayout>
And also
<StackLayout>
<Grid.Row>
<OnPlatform ... />
</Grid.Row>
</StackLayout>
Nothing works
回答1:
Use StaticResource
i.e:
<AbsoluteLayout>
<StackLayout AbsoluteLayout.LayoutBounds="{StaticResource ContainerPosition}" AbsoluteLayout.LayoutFlags="None">
<BoxView AbsoluteLayout.LayoutBounds="{StaticResource BoxPosition}" Color="Maroon"/>
</StackLayout>
<AbsoluteLayout.Resources>
<ResourceDictionary>
<OnIdiom x:Key="BoxPosition" x:TypeArguments="Rectangle" Phone="82,26,60,46" Tablet="111,0,60,46"/>
<OnPlatform x:Key="ContainerPosition" x:TypeArguments="Rectangle" iOS="100,100,100,100" Android="100,80,100,110" Windows="100,120,100,100"/>
</ResourceDictionary>
</AbsoluteLayout.Resources>
</AbsoluteLayout>
回答2:
This answer doesn't work for me. Maybe it's a Grid issue. Error on lines Row, Column, RowSpan, ColumnSpan
<views:BaseDetailsPage.Resources> <ResourceDictionary> <system:Int32 x:Key="PlatformColSpan"> <OnIdiom x:TypeArguments="system:Int32" Phone="2" Tablet="1" /> </system:Int32> <system:Int32 x:Key="PlatformRowSpan"> <OnIdiom x:TypeArguments="system:Int32" Phone="1" Tablet="2" /> </system:Int32> <system:Int32 x:Key="CapsulesRow"> <OnIdiom x:TypeArguments="system:Int32" Phone="1" Tablet="0" /> </system:Int32> <system:Int32 x:Key="CapsulesCol"> <OnIdiom x:TypeArguments="system:Int32" Phone="0" Tablet="1" /> </system:Int32> </ResourceDictionary> </views:BaseDetailsPage.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <views:HomeIndicePreviewView Grid.Row="0" /> <Grid Grid.Row="1"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="0" Grid.RowSpan="{StaticResource PlatformRowSpan}" Grid.ColumnSpan="{StaticResource PlatformColSpan}" Text="Echos"> </Label> <Label Grid.Row="{StaticResource CapsulesRow}" Grid.Column="{StaticResource CapsulesCol}" Grid.RowSpan="{StaticResource PlatformRowSpan}" Grid.ColumnSpan="{StaticResource PlatformColSpan}" Text="Capsules" /> </Grid> </Grid>
回答3:
Correct way is below
AbsoluteLayout.LayoutBounds="{OnIdiom Phone='0.4,0.5,-1,-1',Tablet='0.5,0.5,-1,-1'}"
来源:https://stackoverflow.com/questions/40399224/how-to-use-attached-properties-such-as-grid-row-absolutelayout-layoutflags-to-o