Xamarin.Forms之OnPlatform的使用

1.

<Label x:Name="label">
      <Label.Font>
        <!-- Android font doesn't work -->
        <OnPlatform x:TypeArguments="Font"
                    iOS="Courier New, 10"
                    Android="Droid Sans Mono, 12"
                    WinPhone="Courier New, 15" />
      </Label.Font>
    </Label>
---这种情况下,像x:Double这种类型要每个平台都设值,如果不设,则为0

2.

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

3.使用控件

<ContentView>
        <OnPlatform x:TypeArguments="View">
            <OnPlatform.iOS>
                <Label Text="iOS" />
            </OnPlatform.iOS>
            <OnPlatform.Android>
                <Label Text="Android" />
            </OnPlatform.Android>
        </OnPlatform>
    </ContentView>

OnPlatform必须要包裹在ContentView里面

原文地址:https://www.cnblogs.com/yz1311/p/5549481.html