【发布时间】:2020-04-30 03:41:44
【问题描述】:
我在 Xamarin.Forms 中有一个项目,我正在尝试创建 4 个视图:Android 手机、Android 平板电脑、iPhone 和 iPad。我尝试了一个小例子,在 XAML 中是这样的:
<ContentPage.Content>
<ContentView>
<OnPlatform x:TypeArguments="View">
<On Platform="iOS">
<!-- Use view for iOS here -->
<OnIdiom x:TypeArguments="View">
<OnIdiom.Phone>
<Frame x:Name="MainFrameiPhone">
<StackLayout BackgroundColor="#FF00FF">
</StackLayout>
</Frame>
</OnIdiom.Phone>
<OnIdiom.Tablet>
<Frame x:Name="MainFrameiPad">
<StackLayout BackgroundColor="#00FF00">
</StackLayout>
</Frame>
</OnIdiom.Tablet>
</OnIdiom>
</On>
<!--Same for android -->
<On Platform="Android">
...
</On>
</OnPlatform>
</ContentView>
</ContentPage.Content>
但我不想重命名我在 4 个视图中使用的每个框架和组件(例如 MainFrameiPhone 和 MainFrameiPad)。
我做得对吗?或者我可以创建 4 个视图并从后面的代码中调用每个视图吗?
有什么更好的方法来做到这一点?
谢谢!
【问题讨论】:
标签: xamarin.forms