Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ComboBox in Xamarin forms

How to use ComboBox in Xamarin forms because xamarin forms does not have ComboBox Control, In my application i want to show list of country, so that user can select country(search as well as dropdown)both way, Give me suggestion to resolve this issue Note:I found one solution syncfusion combobox but that is paid service, i don't want paid service

like image 600
P.Thiyagu Avatar asked Apr 03 '19 13:04

P.Thiyagu


3 Answers

Xamarin Forms does include a combo box control, it just isn't called a combo box. XF calls it a Picker. It's pretty easy to use and includes properties you can bind to for ItemSource and SelectedItem/SelectedIndex.

like image 168
Mage Xy Avatar answered Oct 23 '22 01:10

Mage Xy


You can use Picker control at xamarin to achieve list some objects in a box. I recommend you to follow the MVVM pattern to bind datasource and handle events. There is code samples for it that created by Microsoft.

But basically you have to add a Picker to your xaml:

<StackLayout Margin="20">
        <Label Text="Bindable Picker Demo" FontAttributes="Bold" HorizontalOptions="Center" />
        <Picker Title="Select a country" ItemsSource="{Binding CountryList}" SelectedItem="{Binding SelectedColorName, Mode=TwoWay}" />
        
    </StackLayout>

And in your model just set your Countrylist property and It is selected item.

public IList<string> CountryList
    {
        get
        {
            return new List<string> {"USA","Germany","England"};
        }
    }

If you want to make search in your Picker you have to create your own control. According your wishes an Entry and a Listview may be enough. You have to update your list in TextChanged event of Entry.

like image 35
nzrytmn Avatar answered Oct 23 '22 02:10

nzrytmn


You can create your own ListView with ItemsSource as a country list, and SearchView with TextChanged method, where you change your ItemsSource by search value (and firstly, ItemsSource would be empty, because of empty search filter).

Also you can check this link, that could be also useful.

UPDATE:

If you need a searchable Picker, there is a github project, that you can use. It has a search. Link to project.

like image 1
Денис Чорный Avatar answered Oct 23 '22 03:10

Денис Чорный