Xaml Xamarin.Forms的手机和平板电脑视图

Xaml Xamarin.Forms的手机和平板电脑视图,xaml,xamarin.forms,Xaml,Xamarin.forms,我正在尝试制作一款xaml,它在手机和平板电脑上可能会有所不同。我有这样的想法: <OnIdiom x:TypeArguments="View"> <OnIdiom.Phone> <ContentView VerticalOptions="CenterAndExpand"> ... <LineEntry x:Name="User" Style="{StaticResource Sty

我正在尝试制作一款xaml,它在手机和平板电脑上可能会有所不同。我有这样的想法:

<OnIdiom x:TypeArguments="View">
    <OnIdiom.Phone>
        <ContentView VerticalOptions="CenterAndExpand">
            ...
            <LineEntry x:Name="User" Style="{StaticResource Style1}"/>
            ...
        </ContentView>
    </OnIdiom.Phone>
    <OnIdiom.Tablet>
        <ContentView VerticalOptions="End">
            ...
            <LineEntry x:Name="User" Style="{StaticResource Style2}"/>
            ...
        </ContentView>
    </OnIdiom.Tablet>
</OnIdiom>

...
...
...
...

但不能在代码隐藏中使用相同的id名称。我该怎么办?我不想为每个平台使用两个变量(例如userPhone和userTablet)。还有别的办法吗?谢谢

可以使用OnIdiom或OnPlatform更改对象上的大多数属性

<Image Aspect="AspectFit" x:Name="logoImg">
     <Image.HeightRequest>
          <OnPlatform Default="400" Android="350" />
     </Image.HeightRequest>
     <Image.IsVisible>
          <OnIdiom Default="True" Phone="False" />
     </Image.IsVisible>
</Image>

因此,在您的示例中(未测试)


使用
<ContentView>
   <ContentView.VerticalOptions>
      <OnIdiom Default="End" Phone="CenterAndExpand" />
   <ContentView.VerticalOptions>
</ContentView>