简体   繁体   中英

Xamarin.Forms UWP Size of Elements doesn't work

I'm new to 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. 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 . 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 . The default value of VerticalOptions dependency property is LayoutOptions.Fill . And it also works for HorizontalOptions . So if you did not set value for VerticalOptions and HorizontalOptions , the control will fill the whole screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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