Windows phone 7 WP7-将列表框绑定到已筛选的ObservableCollection
我有一个可观察的集合,这是MyObject定义:Windows phone 7 WP7-将列表框绑定到已筛选的ObservableCollection,windows-phone-7,listbox,inotifypropertychanged,Windows Phone 7,Listbox,Inotifypropertychanged,我有一个可观察的集合,这是MyObject定义: public class MyObject : INotifyPropertyChanged { private bool favourite; public event PropertyChangedEventHandler PropertyChanged; public bool Favourite { get { return favour
public class MyObject : INotifyPropertyChanged
{
private bool favourite;
public event PropertyChangedEventHandler PropertyChanged;
public bool Favourite
{
get
{
return favourite;
}
set
{
favourite = value;
var eh = PropertyChanged;
if (eh != null)
{
eh(this, new PropertyChangedEventArgs("Favourite"));
}
}
}
public bool Name { get; set; }
}
我想将此集合绑定到WP7列表框,但只绑定属性为favorite=true的元素。如何将列表框绑定到集合?考虑到ObservableCollection是一个全局变量,它从应用程序的其他部分接收更改(最喜欢的值)
我尝试了但没有成功(当一个元素的收藏夹属性更改时,列表框不会刷新):
ObservableCollection MyChannel=
((App)Application.Current).收藏夹频道
.其中(f=>f.Favorito==true)
.OrderBy(o=>o.SortIndex)
.ToList()).ToObservableCollection();
this.listFavoritos.ItemsSource=MyChannel;
有什么想法吗?在最后一行中,您应该将ListBox的ItemSource设置为MyChannel
this.listFavoritos.ItemSource = myChannels;
在最后一行中,您应该将ListBox的ItemSource设置为MyChannel
this.listFavoritos.ItemSource = myChannels;
最简单的解决方案是创建一个仅包含所需项目的seaparate集合
或者,您可以使用。最简单的解决方案是创建一个仅包含所需项目的seaparate集合 或者,您可以使用一个