我如何使用 Combobox TextSearch 实现contains
代替StartsWith
<rf:ComboBox Grid.Row="1"
Grid.Column="5"
Width="200"
ItemsSource="{Binding Source={StaticResource AccountProvider}}"
DisplayMemberPath="Description"
SelectedValuePath="IndRekId"
IsEmptyItemVisible="True"
SelectedValue="{Binding Id, UpdateSourceTrigger=PropertyChanged}"
IsTextSearchEnabled="True"
TextSearch.TextPath="Description"
IsEditable="True"/>
搜索功能有效,但我需要匹配子字符串
这里我有一个MVVM框架的例子。
我的 xaml 文件:
<ComboBox Name="cmbContains" IsEditable="True" IsTextSearchEnabled="false" ItemsSource="{Binding pData}" DisplayMemberPath="wTitle" Text="{Binding SearchText ,Mode=TwoWay}" >
<ComboBox.Triggers>
<EventTrigger RoutedEvent="TextBoxBase.TextChanged">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsDropDownOpen">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ComboBox.Triggers>
</ComboBox>
我的cs文件:
//ItemsSource - pData
//There is a string attribute - wTitle included in the fooClass (DisplayMemberPath)
private ObservableCollection<fooClass> __pData;
public ObservableCollection<fooClass> pData {
get { return __pData; }
set { Set(() => pData, ref __pData, value);
RaisePropertyChanged("pData");
}
}
private string _SearchText;
public string SearchText {
get { return this._SearchText; }
set {
this._SearchText = value;
RaisePropertyChanged("SearchText");
//Update your ItemsSource here with Linq
pData = new ObservableCollection<fooClass>{pData.ToList().Where(.....)};
}
}
您可以看到可编辑的组合框绑定到字符串(SearchText)
一旦发生 TextChanged 事件,就会显示下拉菜单,并且双向绑定会更新值。
当进入 set{} 时,cs 文件中的 ItemsSource 发生了变化;句法。
https://gist.github.com/tonywump/82e66abaf71f715c4bd45a82fce14d80 https://gist.github.com/tonywump/82e66abaf71f715c4bd45a82fce14d80
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)