使用自定義檢視
你可以使用這些調整工具建立可以整合到頁面的自定義檢視。
選擇 File > New > File... > Forms > Forms ContentView (Xaml) 併為每個特定佈局建立一個檢視:TabletHome.xamland PhoneHome.xaml。
然後選擇 File > New > File... > Forms > Forms ContentPage 並建立一個包含以下內容的 HomePage.cs:
using Xamarin.Forms;
public class HomePage : ContentPage
{
public HomePage()
{
if (Device.Idiom == TargetIdiom.Phone)
{
Content = new PhoneHome();
}
else
{
Content = new TabletHome();
}
}
}
你現在有一個 HomePage 為 Phone 和 Tablet 成語建立了一個不同的檢視層次結構。