2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This KB article explains how to create the image button using Xamarin.Forms button. Create image button with ImageSourceYou can create an image button by using the ImageSource property that is used to set the image in button. In addition, you have to set the value of the ShowIcon property as true.
The following code example shows how to use ImageSource to instantiate an image button.
<button:SfButton ShowIcon="True" BackgroundColor="DeepSkyBlue" HeightRequest="50" WidthRequest="45" CornerRadius="5" ImageSource="alarm.png"/>
The following image illustrates the result of the code. Create image button with contentThe Content property on our button is used to add any content view inside the button. You can use this Content property to create an image button.
The following code example shows how to use Content to instantiate an image button.
<button:SfButton BackgroundColor="DeepSkyBlue" CornerRadius="5" > <button:SfButton.Content> <Grid HeightRequest="45" WidthRequest="100" Margin="15"> <Image Source="alarm.png" /> </Grid> </button:SfButton.Content> </button:SfButton>
The following image illustrates the result of the code. Create image button with textYou can also create an image button with text using the properties Text and ImageSource.
The following code example shows how to create an image button with text and image.
<button:SfButton ImageSource="alarm.png" HeightRequest="50" WidthRequest="95" TextColor="Black" ShowIcon="True" BackgroundColor="DeepSkyBlue" Text="Alarm" CornerRadius="5" >
The following image illustrates the result of the code. You can also change the alignment of the image in the button using the ImageAlignment property as shown in the example below.
<button:SfButton ImageSource="alarm.png" ImageAlignment="End" TextColor="Black" ShowIcon="True" BackgroundColor="DeepSkyBlue" Text="Alarm" CornerRadius="5" >
The following image illustrates the result of the code. A working sample can be downloaded from ImageButton_Sample
See Also:
How to set image in button background
How to create image button with label
How to create button with label and image alignment
Also refer our feature tour page to know more about the features available in our button. |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
testing