过滤绑定到SampleDataSource的列表框 [英] Filter a Listbox bound to SampleDataSource
本文介绍了过滤绑定到SampleDataSource的列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在发布之前已经进行了广泛的搜索,但我找不到解决方案。
I have searched extensively before posting, but I could not find a solution.
推荐答案
你好dloop2
你的简短问题似乎包含几个没有细节的子问题。在显示代码演示时我必须做出一些假设。
我不确定SampleDataSource的细节,让我们把它作为Blend生成的一个简单的,它默认有一个包含2个属性的集合。我假设你只使用属于字符串类型的property1。我假设您将集合拖到列表框中,Blend将生成数据绑定代码,包括:ItemsSource =" {Binding Collection}"
在SampleData文件夹中,找到SampleDataSource.xaml.cs,打开它,找到部分代码:
public class SampleDataSource:System.ComponentModel.INotifyPropertyChanged
  ; {
... public ItemCollection Collection { ...
}
}
如您所见,"收集" property是列表框数据绑定到。
你可以做的是将xaml更改为ItemsSource =" {Binding MatchedCollection}" ,并在该类中添加另一个属性:
Hi dloop2
You brief question seems contain several sub-questions without details. I have to make some assumptions when showing code demo.
I am not sure the detail of the SampleDataSource, lets take it as a simple one that generated by Blend, which default has a collection with 2 properties. I assume you only use the property1 which is string type. I assume you drag the collection to the listbox, which Blend will generate the databinding code, including: ItemsSource="{Binding Collection}"
In the SampleData folder, find the SampleDataSource.xaml.cs , open it, find the partial code of:
public class SampleDataSource : System.ComponentModel.INotifyPropertyChanged
{
...
public ItemCollection Collection
{ ...
}
}
As you can see, that "Collection" property is the listbox databinding to.
What you can do is change the xaml to ItemsSource="{Binding MatchedCollection}" , and add another property in that class:
private ItemCollection _MatchedCollection = new ItemCollection();
public ItemCollection MatchedCollection
{
get{
foreach (ItemCollection item in Collection)
{
if (Textbox.text.Contain(item.Property1)) _MatchedCollection.add item;
}
return _MatchedCollection;
}
}
这篇关于过滤绑定到SampleDataSource的列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文