Xamarin从同一XAML文件中为移动设备和iPad的按钮大小



我正在研究Xamarin表单应用程序,其中我需要在XAML中设计一个页面,在XAML中设计一个页面,我有2个输入字段和一个按钮垂直对齐。

<Entry Placeholder="Username" HorizontalOption="FillAndExpand" HeightRequest="30" WidthRequest="100" BackgroundColor="#3079a8" TextColor="Black" />
<Entry Placeholder="Password" HorizontalOption="FillAndExpand" HeightRequest="30" WidthRequest="100" BackgroundColor="#3079a8" TextColor="Black" />
<Button Text="Login" HorizontalOption="FillAndExpand" HeightRequest="30" WidthRequest="100" BackgroundColor="#3079a8" TextColor="White" />

我也想使用相同的XAML文件进行手机,但是如何提供Heightrequest和widthrequest,以便该按钮可以根据电话广告iPad的屏幕大小进行调整。

您可以使用Device.Idiom根据PhoneTablet更改参数:

<Button Text="StackOverflow" BackgroundColor="Blue">
    <Button.WidthRequest>
        <OnIdiom x:TypeArguments="x:Double" Phone="200" Tablet="400" />
    </Button.WidthRequest>
</Button>

您也可以使用onplatform:

<stacklayout>
<Button Text="Tap Me">
 <Button.WidthRequest>
    <OnPlatform x:TypeArguments="x:Double">
                      <On Platform="iOS">80</On>
                      <On Platform="Android,Windows">70</On>
            </OnPlatform>
</Button.WidthRequest>
  </Button>
</stacklayout>

最新更新