![](/img/trans.png)
[英]Adding new element to a ComboBox which is in a DataGrid in WPF using MVVM
[英]Adding Filter TextBox to a ComboBox using MVVM in WPF
从ComboBox
控件使用IsTextSearchEnabled
,如下所示:
<ComboBox IsTextSearchEnabled="True" IsTextSearchCaseSensitive="True or False depending on your scenario" />
在我的项目中,当我做这样的事情时,我在下拉式内容模板中添加了一个TextBox作为第一项,随后是一个演示者,紧随其后的是需要数据绑定的项。
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=FilteredText"} Mode="TwoWay"/>
<ListBox ItemSource="{Binding Path=ItemsForBinding}" Mode="TwoWay" NotifyOnSourceUpdated="True" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
并且在您的视图模型中,确保在更新FilteredText属性时为NotifyOnProperyChanged启用了它,它将触发绑定项的“删除”,我通常使用ObservableCollection,但是我知道ListCollectionView具有过滤和通知的功能集合更改时的UI。 您甚至可以找到第三方文本AutoCompleteBox(我使用Telerik,),它可以让您在“文本框”中预先填充您希望用户能够过滤的字词。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.