我一直在开发支持 iOS 和 Android 平台的 Xamarin.Forms 应用程序。 UI 主要是使用 Forms PCL 项目中的 XAML 构建的。我知道可以通过代码使用
if(Device.OS == TargetPlatform.iOS && Device.Idiom == TargetIdiom.Tablet)
如何通过 XAML 为 iPad 构建新的 UI?
最佳答案
你可以在xaml中使用成语值OnIdiom
:
<Grid VerticalOptions="FillAndExpand">
<Grid.ColumnSpacing>
<OnIdiom x:TypeArguments="x:Double"
Phone="20"
Tablet="40"/>
</Grid.ColumnSpacing>
</Grid>
有了这个,您可以在 xaml 中为手机或平板电脑设置不同的值。
当您的页面设计对于手机和平板电脑有很大不同时,您最好实现两个不同的页面并导航到正确的页面,使用您在问题中发布的 idom 代码:
if (Device.Idiom == TargetIdiom.Tablet || Device.Idiom == TargetIdiom.Desktop)
await Navigation.PushAsync(new TabletPage());
else
await Navigation.PushAsync(new Page());
看this blog post来自 James Montemagno,它准确地描述了您的问题。
*编辑:根据习语在 2 个 ContentView
之间切换可以用完全相同的方式完成:
XAML:
<ContentPage x:Name="MyPage"></ContentPage>
代码隐藏:
if (Device.Idiom == TargetIdiom.Tablet || Device.Idiom == TargetIdiom.Desktop)
MyPage.Content = new LargeDisplayContentView();
else
MyPage.Content = new SmallDisplayContentView();
关于c# - 使用 xaml 在 Xamarin.Forms 中为 iPhone 和 iPad 分离 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34715613/