当然可以。最简单的方法是在 XAML 中使用OnPlatform(请参阅here)标签
<OnPlatform x:TypeArguments="View">
<On Platform="iOS">
<!-- Use view for iOS here -->
</On>
<On Platform="Android">
<!-- Use view for Android here -->
</On>
<On Platform="UWP">
<!-- Use view for UWP here -->
</On>
</OnPlatform>
在您的情况下(对 Android 和 iOS 使用相同的视图),您可以将其简化为
<OnPlatform x:TypeArguments="View">
<On Platform="iOS, Android">
<!-- Use view for iOS here -->
</On>
<On Platform="UWP">
<!-- Use view for UWP here -->
</On>
</OnPlatform>
如果你在代码中创建视图,你可以使用Device.RuntimePlatform
View CreateViewForCurrentPlatform()
{
switch(Device.RuntimePlatform)
{
case Device.iOS:
case Device.Android:
return new View1();
case Device.UWP:
return new View2();
}
throw new Exception("Unsupported platform");
}
不管怎样,既然你这么说
[...] 对于 UWP 桌面应用,它可能具有更多可用控件,因为屏幕空间更大。
您应该考虑改用Device.Idiom(请参阅here),它可以让您区分平板电脑、台式机和手机。 Android 和 iOS 也在平板电脑上运行,如果在平板电脑上浪费屏幕空间,那就太可惜了。