WPF组合框,当文本属性更改时从数据库更新其ItemsSource

WPF组合框,当文本属性更改时从数据库更新其ItemsSource,wpf,search,combobox,itemssource,Wpf,Search,Combobox,Itemssource,我想在表单上有一个ComboBox控件,用于在用户输入时搜索投资列表。如果我在启动时缓存数据库中的全部投资集合(目前约3000项),我可以轻松地做到这一点,但如果没有必要,我宁愿不这样做 我试图实现的行为是: 用户在可编辑组合框中键入文本。 当用户输入每个字符时,就会触发数据库搜索功能,从而在每次连续击键时缩小搜索结果的范围。 随着搜索结果的更新,下拉面板将打开并显示相关匹配项 我已尝试将ComboBox的Text属性绑定到我的ViewModel上的InvestmentName字符串属性,并将C

我想在表单上有一个ComboBox控件,用于在用户输入时搜索投资列表。如果我在启动时缓存数据库中的全部投资集合(目前约3000项),我可以轻松地做到这一点,但如果没有必要,我宁愿不这样做

我试图实现的行为是:

用户在可编辑组合框中键入文本。 当用户输入每个字符时,就会触发数据库搜索功能,从而在每次连续击键时缩小搜索结果的范围。 随着搜索结果的更新,下拉面板将打开并显示相关匹配项 我已尝试将ComboBox的Text属性绑定到我的ViewModel上的InvestmentName字符串属性,并将ComboBox的ItemsSource属性绑定到我的ViewModel上的InvestmentList通用列表属性。当我这样做时,文本属性从ItemsSource自动完成,但是下拉列表显示为空

我已经能够使用堆叠在列表框顶部的文本框来实现这些结果,但它不是很优雅,而且占用了更多的屏幕空间。我还能够让它与堆叠在组合框顶部的文本框一起工作,尽管当IsDropDownOpen属性设置为true且存在有效搜索项时,组合框会窃取焦点。使用两个控件也不是很美观

我觉得我真的很接近让它以我想要的方式工作,但是有一些事情我逃避了

此控件的XAML为:

<ComboBox Height="23" Width="260" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left"
          ItemsSource="{Binding InvestmentList}" DisplayMemberPath="FullName"
          IsDropDownOpen="{Binding DoShowInvestmentList}"
          ItemsPanel="{DynamicResource ItemsTemplate}" IsEditable="True" 
          Text="{Binding Path=InvestmentName, Mode=TwoWay,
                 UpdateSourceTrigger=PropertyChanged}" />

我对此做了大量的研究,但还没有找到答案。

请查看这篇关于CodeProject的伟大文章,作者是。。。我:


请看最后的Google suggest示例,它与您需要的类似,每个按键都会触发对服务器的另一个查询。

谢谢!这正是我想要的。
    private bool _doShowInvestmentList;
    public bool DoShowInvestmentList
    {
        get { return _doShowInvestmentList; }
        set { if (_doShowInvestmentList != value) { _doShowInvestmentList = value; RaisePropertyChanged("DoShowInvestmentList"); } }
    }

    private List<PFInvestment> _investmentList;
    public List<PFInvestment> InvestmentList
    {
        get { return _investmentList; }
        set { if (_investmentList != value) { _investmentList = value; RaisePropertyChanged("InvestmentList"); } }
    }

    private string _investmentName;
    public string InvestmentName
    {
        get { return _investmentName; }
        set
        {
            if (_investmentName != value)
            {
                _investmentName = value;
                this.InvestmentList = DataAccess.SearchInvestmentsByName(value).ToList();

                if (this.InvestmentList != null && this.InvestmentList.Count > 0)
                    this.DoShowInvestmentList = true;
                else
                    this.DoShowInvestmentList = false;

                RaisePropertyChanged("InvestmentName");
            }
        }
    }