繁体   English   中英

Xamarin从同一XAML文件为移动设备和ipad形成按钮大小

[英]Xamarin forms Button size for mobile and ipad from same XAML file

我正在xamarin表单应用程序上工作,在该应用程序中我有一个必须在XAML中设计页面的要求,我有2个输入字段和一个在stacklayout内垂直对齐的按钮。

<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,以便Button可以根据电话广告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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM