Reputation: 368
Good day. I'm creating an app in Xamarin, I come from an Android background, in Android Studio It was not necessary to set the component size manually because I could choose match_parent or wrap_content. is there something similar in Xamarin.Forms?
I have tried using Horizontal and Vertical Options but neither seems to works. The image simply doesn't fit. I guess it's because im trying to fit the image in a button.
As you can see below the size is incorrect I've tried to set the Padding with no success whatsoever, using the button Padding or even with another StackLayout's Padding. is there any other solution than using image component and setting a listener in it for the click?
Upvotes: 2
Views: 163
Reputation: 14956
like pinedax said,you could use ImageButton
,after you set HorizontalOptions and VerticalOptions,you could limit its size by HeightRequest and WidthRequest,Aspect property size the image within the bounds it is being displayed within (whether to stretch, crop or letterbox),you could also set a click listener in it like Button:
<ImageButton Source="play_button.png" WidthRequest="300" HeightRequest="300" Aspect="Fill" HorizontalOptions="Center" VerticalOptions="Center" Clicked="ImageButton_Clicked"></ImageButton>
in behind code:
private void ImageButton_Clicked(object sender, EventArgs e)
{
Console.WriteLine("clicked");
}
Upvotes: 1
Reputation: 9346
I believe that the Control you are looking to use is the ImageButton
. With the VerticalOptions and HorizontalOptions you should be able to center propertly the Control.
<ImageButton Source="blue-play-button.png"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
Hope this helps.-
Upvotes: 1