[英]Xamarin.Forms I want comboBox like a windows forms combobox
認為這是不可能的,但您可以在這篇文章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.