[FIXED] Xamarin.Forms I want comboBox like a windows forms combobox

Issue

Im looking for better picker because Xamarin.Forms picker is really bad and I dont want like that, Is there any custom picker or something like comboBox?

i want Like This

Solution

You could use Xamarin.Forms.ComboBox. Install it from Manage NuGet Packages.

Xaml:

  <combobox:ComboBox x:Name="comboBox" 
                           ItemsSource="{Binding ItemsSource}"                                   
                           SelectedItemChanged="ComboBox_SelectedItemChanged"                                
                           Visual="Material">
            <combobox:ComboBox.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Label Text="{Binding .}" Padding="5,5,0,0"/>
                    </ViewCell>
                </DataTemplate>
            </combobox:ComboBox.ItemTemplate>
        </combobox:ComboBox>

Code:

public partial class Page3 : ContentPage
{
    public Page3()
    {
        InitializeComponent();
        this.BindingContext=new Page3ViewModel();
    }

    private void ComboBox_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
    {
        comboBox.Text = comboBox.SelectedItem.ToString();
    }       
}

public class Page3ViewModel
{
    public List<string> ItemsSource { get; set; }   
    public Page3ViewModel()
    {
        ItemsSource = new List<string>()
        {
            "Item1",
            "Item2",
            "Item3",
            "Item4"
        };

    }
  }
  }

enter image description here

Answered By – Wendy Zang – MSFT

Answer Checked By – Dawn Plyler (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published