简体   繁体   English

是否可以将XAML ItemSource绑定到Where查询生成的IEnumerable?

[英]Is is possible to bind a XAML ItemSource to an IEnumerable generated by a Where query?

I am creating a Windows Phone Application and would like to use Pivots to show different views into the same data. 我正在创建Windows Phone应用程序,并希望使用数据透视表将不同的视图显示到同一数据中。

To do this, I created properties: 为此,我创建了属性:

IEnumerable<Item> Items { get; set; };
IEnumerable<Item> ItemView1 { get { return Items.where(value => value.Property) }};        
IEnumerable<Item> ItemView2 { get { return Items.where(value => value.Property) }};

And then I bound to them in my view: 然后我认为它们绑定了它们:

<phone:PivotItem>
    <phone:LongListSelector ItemsSource="{Binding ItemView1}">
</phone:PivotItem>

<phone:PivotItem>
    <phone:LongListSelector ItemsSource="{Binding ItemView2}">
</phone:PivotItem>

And after adding items to the Items property, I call: 将项目添加到Items属性后,我调用:

NotifyPropertyChanged("ItemView1");
NotifyPropertyChanged("ItemView2");

How ever, when I run the application, my view does not get updated with the new results but it works if I create new lists. 但是,当我运行该应用程序时,我的视图不会使用新结果进行更新,但是如果创建新列表,它将起作用。 Is it not possible to bind directly to the result like this? 这样不可能直接绑定到结果吗? If not, is there any suggested way I should be doing something like this, hopefully without having to build multiple lists all the time? 如果没有,有什么建议的方法可以做这样的事情,希望不必一直建立多个列表?

You're raising the wrong event. 您提出了错误的事件。

Simple content bound controls, like text blocks, etc., autowire up to INotifyPropertyChanged, if the context object implements that interface, but collection based controls (I think selector based as well) look for INotifyCollectionChanged. 如果上下文对象实现该接口,则简单的内容绑定控件(例如文本块等)会自动连接到INotifyPropertyChanged,但是基于集合的控件(我也认为基于选择器)会寻找INotifyCollectionChanged。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM