我有一個ObservableCollection,這是MyObject來定義:WP7 - 綁定列表框來過濾的ObservableCollection
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列表框,但只有具有財產最喜歡的元素=真。我應該如何將列表框綁定到集合?考慮到ObservableCollection(全局變量)從應用程序的其他部分接收更改(Favorite值)。
我想這沒有成功(當一個要素變化最喜歡的屬性,列表框不刷新):
ObservableCollection<Channel> myChannels =
(((App)Application.Current).FavouriteChannels
.Where(f=>f.Favorito == true)
.OrderBy(o => o.SortIndex)
.ToList()).ToObservableCollection<Channel>();
this.listFavoritos.ItemsSource = myChannels;
任何想法?