As we know in android we can use
android:width='wrap_content'
android:height='match_parent'
to set width or height of the views.
but, in xamarin forms we cannot use that.
so how can i set dynamic width or height for my xamarin forms component?
like match_parent or wrap_content in android
In Xamarin.Forms you do the same using the LayoutOptions.
Let's say you have a Button which you want to grow horizontally (width) as its parent grow, you use:
var button4 = new Button {Text = "Click Me!", HorizontalOptions=LayoutOptions.FillAndExpand, VerticalOptions=LayoutOptions.Center};
LayoutOptions.FillAndExpand means it will take all the posible space available in its parent view (with some exceptions).
in XAML that'd be:
<Button Text="Click Me!"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center" />
Suggest you to see the Getting Started of Xamarin Forms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With