How can I set the width of an image inside a button in Xamarine.Forms xaml?
I would like to know if it is possible to set the width and height of the image inside this button:
<Button Image="ic_music_white.png" BorderWidth="1" BorderColor="White" HeightRequest="56" BackgroundColor="PowderBlue" HorizontalOptions="Center" Clicked="Button_Clicked">
</Button>
Any solution?
source to share
You can always create an Image control and add a gesture recognizer to it. This way you have more control over the size and placement of the image.
XAML
<Image x:Name="myImage" Source="ic_music_white.png" HeightRequest="56" BackgroundColor="PowderBlue" HorizontalOptions="Center"/>
XAML.CS
TapGestureRecognizer tapEvent = new TapGestureRecognizer();
tapEvent.Tapped += Button_Clicked;
myImage.GestureRecognizers.Add(tapEvent);
source to share
This is not possible from a Xamarin.Forms project, but you can create your own renderers that will allow you to change the properties of an embedded control.
For iOS, you will be modifying ImageEdgeInsets .
For Android, you can take a look at Button renderer so you can get any ideas.
Hope it helps.
source to share
No, you cannot control the height / width of the image inside button
. The best option would be to create a stack layout and then put text and image in it. How I did it:
<StackLayout Grid.Row="2" Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="End" HeightRequest="60">
<Label Text="Review task" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand" FontSize="25" FontAttributes="Bold"/>
<Image Source="nextarrow_white.png" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" HeightRequest="32" Margin="20,4,0,0"/>
</StackLayout>
source to share