1 回答
TA贡献1868条经验 获得超4个赞
我做了类似的事情,但我通过文本框过滤。也许它会帮助你。
.Xaml 如下
<TextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"
Background="{x:Null}"
Text="{Binding Item , UpdateSourceTrigger=LostFocus}" Margin="6,0,0,0" BorderThickness="0" PreviewKeyDown="ItemField_PreviewKeyDown" TextChanged="ItemField_TextChanged" IsReadOnly="{Binding IsReadonly}" />
.Xaml.cs 如下
private ObservableCollection<ItemGrid> _itemGrid = new ObservableCollection<ItemGrid>();
public ObservableCollection<ItemGrid> ItemGrid
{
get
{
return _itemGrid;
}
set
{
_itemGrid = value;
}
}
private void ItemField_TextChanged(object sender, TextChangedEventArgs e)
{
if (isBeginingEdit) return;
//here we show the item selector and take care of autocomplete
var textBox = sender as TextBox;
if (textBox.Text != "")
{
var _itemSourceList = new CollectionViewSource() { Source = ItemGrid };
ICollectionView Itemlist = _itemSourceList.View;
ItemSearchText = textBox.Text;
Itemlist.Filter = ItemFilter;
var count = _itemSourceList.View.Cast<ItemGrid>().Count();
if (count > 0)
{
ItemsGrid.ItemsSource = Itemlist;
}
}
}
- 1 回答
- 0 关注
- 196 浏览
添加回答
举报