我在WPF中有可编辑的组合框。其具有订单号列表。我需要在代码中实现以下场景。用户可以填写起始订单号,系统在下拉列表中提出可用的关闭订单号。
有人能建议怎么做吗?
在我的Viewmodel中,我写道:
public void _fillREOrderNumbers()
{
List<FinishedReprintingOrderNumber> orders = _finishedProductReprintService.GetFinishedProductReprintbyOrder().ToList();
foreach (var item in orders)
{
ReOrders.Add(item);
}
}
这是在下拉列表中加载订单号。
查看或XAML:
<ComboBox x:Name="cbOFab" HorizontalAlignment="Left" Margin="373,81,0,0"
VerticalAlignment="Top" Width="262" IsEditable="True"
ItemsSource="{Binding ReOrders, Mode=TwoWay}" DisplayMemberPath="codOrder" SelectedItem="{Binding
ReSelectedOrder}" Background="{DynamicResource dgridRowColor}" />
直到现在,我可以在组合框中填充订单号,但我不知道如何在里面搜索。
我已经用这种方式实现了对组合框中项目的过滤。
这是XAML:
<ComboBox
MinWidth="200"
ItemsSource="{Binding Path=Shops.View, RelativeSource={RelativeSource TemplatedParent}}"
DisplayMemberPath="NameExtended"
SelectedItem="{Binding Path=SelectedShop, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
IsTextSearchEnabled="False"
IsEditable="True"
IsDropDownOpen="{Binding Path=ComboOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
StaysOpenOnEdit="True"
Text="{Binding Path=SearchText, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<i:InvokeCommandAction
Command="{Binding Path=FilterCommand, RelativeSource={RelativeSource TemplatedParent}}"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
您需要IsTextSearchEnabled及以下的所有行。
当您按下组合框中的任何键时,它会打开并过滤其中的项目,使用绑定到组合框的属性SearchText。文本
这是视图模型代码:
public string SearchText { get; set; }
private List<Shop> _shops;
protected void FilterShops()
{
ComboOpen = true;
if (!string.IsNullOrEmpty(SearchText))
{
Shops.UpdateSource(_shops.Where(s => s.NameExtended.ToLower().Contains(SearchText.ToLower())));
}
else
{
Shops.UpdateSource(_shops);
}
OnPropertyChanged("Shops");
}