How to use attached properties such as Grid.Row, AbsoluteLayout.LayoutFlags to OnPlatform tag in Xamarin Forms

纵饮孤独 提交于 2021-01-24 10:49:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!