[英]Separate UI for iPhone and iPad in Xamarin.Forms using xaml
我一直在開發支持 iOS 和 Android 平台的 Xamarin.Forms 應用程序。 UI 主要是使用 Forms PCL 項目中的 XAML 構建的。 我知道可以通過代碼使用
if(Device.OS == TargetPlatform.iOS && Device.Idiom == TargetIdiom.Tablet)
如何通過 XAML 為 iPad 構建新的 UI?
您可以在 xaml 中使用 Idiom 值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());
查看 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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.