新的OnPlatform / OnIdiom XAML扩展-边距厚度的用法

时间:2018-10-21 10:04:47

标签: xaml xamarin.forms

在Xamarin.Forms 3.2.0中,Xamarin Forms引入了新的新 OnPlatform / OnIdiom XAML扩展

根据blog,我们可以重新编写以下代码,

import math
def count_primes(num):
    current_number = 4
    number_of_prime = 2
    while current_number <= num:
        is_prime = True
        if current_number%2==0:
            is_prime = False
            current_number += 1
            continue
        else:
            limit = math.ceil(current_number ** 0.5)+1
            for i in range(3, limit, 2):
                if current_number%i==0:
                    is_prime = False
                    #current_number += 1 #first increment
                    continue
                    #This continue statement does not skip the next lines (after the for loop) so you increment current_number twice
        if is_prime == True:
            print(current_number)
            number_of_prime += 1
        current_number += 1 #second increment
    return number_of_prime
count_primes(100)

带有新扩展名。

<Button Text="Extensions" BackgroundColor="Black" TextColor="White">
<Button.HeightRequest>
     <OnPlatform x:TypeArguments="x:Double" Default="40">
        <On Platform="iOS" Value="60"/>
        <On Platform="Android" Value="80"/>
    </OnPlatform>
</Button.HeightRequest>

我的疑问是我如何才能将相同的 OnIdiom XAML扩展重复用于边距/厚度。

1 个答案:

答案 0 :(得分:7)

您应该可以这样做:<Button Margin="{OnPlatform Android='10,5,10,0', iOS='10,20,10,0'}" />

由您自己决定更喜欢哪种语法!