We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create Xamarin.Forms image button?

Platform: Xamarin.Forms |
Control: SfButton

This KB article explains how to create the image button using Xamarin.Forms button.

Create image button with ImageSource

You 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.

ImageButton using ImageSource

Create image button with content

The 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.

ImageButton using Content

Create image button with text

You 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.

ImageButton with TextContent and Image

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.

ImageButton with TextContent and ImageAlignment

A working sample can be downloaded from ImageButton_Sample

 

See Also:

 

How to create simple button

 

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.
ADD COMMENT
You must log in to leave a comment
Comments
Karthik E [Syncfusion]
Apr 29, 2021

testing

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile