簡體   English   中英

Xamarin.Forms 我想要像 windows 窗體組合框一樣的組合框

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

我正在尋找更好的選擇器,因為 Xamarin.Forms 選擇器真的很糟糕,我不想那樣,是否有任何自定義選擇器或類似組合框的東西?

我想要這樣

認為這是不可能的,但您可以在這篇文章Apply styles on Picker items in Xamarin Forms之后創建自定義選擇器對話框設計。

按照上一個答案,您還可以使用SyncFusion Xamarin ComboBox ,但它可能需要許可證(不確定)

該網站包含有關它的信息以及如何設置它的代碼示例和示例,還有其他“類型”的組合框。

您可以使用Xamarin.Forms.ComboBox Manage NuGet Packages安裝它。

xml:

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

代碼:

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

    }
  }
  }

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM