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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to Add image and button in the Drop down items

Platform: Xamarin.Forms |
Control: SfAutoComplete |
Published Date: April 7, 2017 |
Last Revised Date: June 24, 2019

Syncfusion Autocomplete in Xamarin provides a support to add image and buttons in the popup.

 

To add image and button for drop down in Autocomplete follow the below given procedure:

 

Step 1: Create the autocomplete sample with all necessary assemblies.

Step 2: Add necessary images in the Drawable folder that has to be shown on to the drop-down list.

Step 3: Use the below code snippets as such to get the exact output.

 

The below code illustrates the way to achieve this.

Xaml Code:

<ContentPage.Resources>
<ResourceDictionary>
  <DataTemplate x:Key="itemTemplate">
      <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" Padding="5,0,0,0" >
          <Image Source="{Binding Image}" HeightRequest="40" WidthRequest="40" Aspect="AspectFit"/>
          <Button Text="{Binding Label}" TextColor="Black" WidthRequest="200" />
      </StackLayout>
  </DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
 
<ContentPage.Content>
<StackLayout Padding="50" >
  <autocomplete:SfAutoComplete x:Name="autocomplete" DisplayMemberPath="Label" MaximumDropDownHeight="260" DropDownItemHeight="50" ItemTemplate="{StaticResource itemTemplate}" DataSource="{Binding ItemsCollection}" HeightRequest="60" WidthRequest="400" />
</StackLayout>
</ContentPage.Content>

 

Code Behind Code:

namespace Autocomplete
{
public partial class AutocompletePage : ContentPage
{
public AutocompletePage()
{
    InitializeComponent();
    autocomplete.BindingContext = new AutoCompleteViewModel();
}
public class AutoCompleteModel
{
    public AutoCompleteModel(string label, string imagestr)
    {
        Label = label;
        Image = imagestr;
 
    }
    private string _label;
 
    public string Label
    {
        get { return _label; }
        set { _label = value; }
    }
    private string _image;
 
    public string Image
    {
        get { return _image; }
        set { _image = value; }
    }
}
public class AutoCompleteViewModel
{
    public AutoCompleteViewModel()
    {
        ItemsCollection.Add(new AutoCompleteModel("Uganda", "image1.png"));
        ItemsCollection.Add(new AutoCompleteModel("Ukraine", "image2.png"));
        ItemsCollection.Add(new AutoCompleteModel("United States", "image3.png"));
        ItemsCollection.Add(new AutoCompleteModel("United Kingdom", "image4.png"));
        ItemsCollection.Add(new AutoCompleteModel("Uzbekisthan", "image5.png"));
    }
    private ObservableCollection<AutoCompleteModel> itemsCollection = new ObservableCollection<AutoCompleteModel>();
 
    public ObservableCollection<AutoCompleteModel> ItemsCollection
    {
        get { return itemsCollection; }
        set { itemsCollection = value; }
    }
}
}
}
 

 

Image for Image and Button on Drop Down Items:

Add image and button in dropdown

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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