美文网首页代码片段分享
Xamarin forms 在代码中判断当前系统平台

Xamarin forms 在代码中判断当前系统平台

作者: 花艺荣 | 来源:发表于2019-08-09 17:13 被阅读0次

OnPlatform 允许您根据平台更改XAML中的属性:

<ContentPage>
 <ContentPage.Padding>
     <OnPlatform x:TypeArguments="Thickness">
         <On Platform="Android, UWP">0</On>
         <On Platform="iOS">0,20,0,0</On>
     </OnPlatform>
 </ContentPage.Padding>
</ContentPage>

代码中这么做:

switch(Device.RuntimePlatform)
{
  case Device.iOS:
      this.Padding = new Thickness(0,20,0,0);
      break;
  case Device.Android:
  case Device.UWP:   
  case Device.macOS:
  default:
      // This is just an example. You wouldn't actually need to do this, since Padding is already 0 by default.
      this.Padding = new Thickness(0);
      break;
}

参考地址:
https://xamarinhelp.com/xamarin-forms-onplatform-runtimeplatform/

相关文章

网友评论

    本文标题:Xamarin forms 在代码中判断当前系统平台

    本文链接:https://www.haomeiwen.com/subject/hvghjctx.html