使用自定义视图
你可以使用这些调整工具创建可以集成到页面的自定义视图。
选择 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 成语创建了一个不同的视图层次结构。