【问题标题】:Phone and Tablet View for Xamarin.FormsXamarin.Forms 的手机和平板电脑视图
【发布时间】:2020-01-27 14:53:57
【问题描述】:

我正在尝试制作一个可以在手机和平​​板电脑中不同的 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 名称。我能怎么做?我不想为每个平台使用 2 个变量(例如 userPhone 和 userTablet)。有另一种方法来实现吗?谢谢!

【问题讨论】:

标签: xaml xamarin.forms


【解决方案1】:

可以使用 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-20
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多