简体   繁体   中英

Xamarin.Forms I want comboBox like a windows forms combobox

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

认为这是不可能的,但您可以在这篇文章Apply styles on Picker items in Xamarin Forms之后创建自定义选择器对话框设计。

Following the previous answer, you could also use SyncFusion Xamarin ComboBox , tho it might need a license (not sure)

The Website contains information about it as well as code samples and examples on how to set it up, also have other "Types" of ComboBox.

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"
        };

    }
  }
  }

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM