代码之家  ›  专栏  ›  技术社区  ›  Alan2

在Xamarin Forms代码背后是否有任何新的方法来执行OnPlatform检查?

  •  0
  • Alan2  · 技术社区  · 4 年前

    我有这个Xaml

    Margin="{OnPlatform Android='20,0,20,0', iOS='20,0,20,30'}"
    

    我正在将Xaml更改为C#

    现在还有比使用这样的东西更好的选择吗:

    switch(Device.RuntimePlatform)
    
    0 回复  |  直到 4 年前
        1
  •  1
  •   Gerald Versluis    4 年前

    根据 the Docs 没有。你仍然需要使用这样的东西:

    double top;
    switch (Device.RuntimePlatform)
    {
      case Device.iOS:
        top = 20;
        break;
      case Device.Android:
      case Device.UWP:
      default:
        top = 0;
        break;
    }
    layout.Margin = new Thickness(5, top, 5, 0);
    

    C# Markup 现在,这可能会使语法更容易一些吗?请注意,该功能已移动/正在移动到 Xamarin Community Toolkit