如何在文本搜索上过滤wpf ComboBox
我的XAML代码
<Window x:Class="WpfApplication5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox HorizontalAlignment="Left" IsEditable="True" IsTextSearchEnabled="True" ItemsSource="{Binding customerCollection}" SelectedItem="{Binding SelectedCustomer}" SelectedValuePath="CustomerId" DisplayMemberPath="Name" Margin="183,146,0,0" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.514,0.39"/>
</Grid>
MVVM代码
public class CustomerModel
{
public int CustomerId { get; set; }
public String Name { get; set; }
}
public class CustomerViewModel
{
public CustomerViewModel()
{
customerCollection = new ObservableCollection<CustomerModel>();
customerCollection.Add(new CustomerModel() { CustomerId = 1, Name = "A" });
customerCollection.Add(new CustomerModel() { CustomerId = 2, Name = "AA" });
customerCollection.Add(new CustomerModel() { CustomerId = 3, Name = "AAA" });
customerCollection.Add(new CustomerModel() { CustomerId = 4, Name = "BAAA" });
customerCollection.Add(new CustomerModel() { CustomerId = 5, Name = "BB" });
customerCollection.Add(new CustomerModel() { CustomerId = 6, Name = "CC" });
customerCollection.Add(new CustomerModel() { CustomerId = 7, Name = "CCCC" });
customerCollection.Add(new CustomerModel() { CustomerId = 8, Name = "DFF" });
customerCollection.Add(new CustomerModel() { CustomerId = 9, Name = "ABC" });
}
public ObservableCollection<CustomerModel> customerCollection { get; set; }
private CustomerModel _SelectedCustomer = new CustomerModel();
public CustomerModel SelectedCustomer
{
get { return _SelectedCustomer; }
set
{ _SelectedCustomer = value; }
}
}
如何在ComboBox的文本框中显示已过滤的项目。?
这里我想在ComboBox上显示项目是搜索文本的客户。
答案 0 :(得分:0)
不幸的是,在组合框控件中没有这样的内置属性。但是,您可以使用此autocomplete textbox/combobox user control来实现此目的。
答案 1 :(得分:0)
您可以尝试https://www.nuget.org/packages/THEFilteredComboBox/ 这是我们公司开发和使用的控件(目前处于测试阶段)