如何筛选WPF组合框? [英] How to filter my WPF-combobox?

查看:33
本文介绍了如何筛选WPF组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:抱歉英语不好,不是我的母语.

我目前正在一个项目中,我有一个要在组合框中列出的人员列表.我希望对组合框进行过滤,以便只列出我要搜索的人.

例如,如果我在组合框中输入"Joh",则应该只有以"Joh"开头的人,例如"John","Johann",....

接下来的事情是,我的组合框不可编辑",我如何使它可以写在其中?当前它是锁定的" ...

希望您能理解我的问题以及解决方法!

解决方案

这实际上是内置的!

您需要做的是在 ComboBox 控件上设置以下属性.

 < ComboBox ItemsSource ="{Binding PersonList}"IsTextSearchEnabled ="True"TextSearch.TextPath ="Name"/> 

此示例假设您具有类型为 Person PersonList ,其中类型 Person 的属性为 Name .

您需要将 TextSearch.TextPath 设置为要搜索的任何属性(基于 ItemsSource 集合中各项的属性)./p>

更多信息,请参见 https://msdn.microsoft.com/zh-CN/library/windows/apps/windows.ui.xaml.controls.combobox.istextsearchenabled

first of all: sorry for the bad english, its not my first language.

I am currently working on a project where i have a list of persons which i want to list up in a combobox. I want the combobox to get filtered, so that there are only the people listed up i am searchig for.

For example if i type in the combobox "Joh", there should only be people who start with "Joh" like "John", "Johann", ... .

The next thing is, my combobox is not "editable", how can i make it that i can write in it ? Currently it is "locked" ...

I hope you understand whats my problem, and how to solve it!

解决方案

This is actually built in!

What you need to do is set the following properties on your ComboBox control.

<ComboBox ItemsSource="{Binding PersonList}"
          IsTextSearchEnabled="True" 
          TextSearch.TextPath="Name"/>

This example assumes you have a PersonList of type Person, in which type Person has a property of Name.

You'll want to set the TextSearch.TextPath to whatever property you want to search on (based on a property of the items in your ItemsSource collection).

More info, see https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.combobox.istextsearchenabled

这篇关于如何筛选WPF组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆