![](/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.