简体   繁体   English

Xamarin.Forms UWP元素大小不起作用

[英]Xamarin.Forms UWP Size of Elements doesn't work

I'm new to Xamarin. 我是Xamarin的新手。 When I try to insert a Button or a BoxView I can set the "HeightRequest" and "WidthRequest" Parameters but the elements are just filling the whole screen. 当我尝试插入Button或BoxView时,我可以设置“ HeightRequest”和“ WidthRequest”参数,但是元素仅填充整个屏幕。 What am I doing wrong? 我究竟做错了什么?

You have done nothing wrong, but you missed some key procedure. 您没有做错任何事情,但是错过了一些关键过程。 you did not set LayoutOptions of Button or BoxView . 您没有设置LayoutOptionsButtonBoxView The following code could make element size effected. 以下代码可以使元素大小生效。

<Button Text="click me" 
 HeightRequest="44"
 WidthRequest="60" 
 VerticalOptions="Start"
 HorizontalOptions="Start"/>

As you know, the button control is inherited from the View . 如您所知,按钮控件是从View继承的。 The default value of VerticalOptions dependency property is LayoutOptions.Fill . VerticalOptions依赖项属性的默认值为LayoutOptions.Fill And it also works for HorizontalOptions . 它也适用于HorizontalOptions So if you did not set value for VerticalOptions and HorizontalOptions , the control will fill the whole screen. 因此,如果您没有为VerticalOptionsHorizontalOptions设置值,则控件将填满整个屏幕。

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

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