我正在寫windows phone 8.1通用應用程序,並且主要應用程序控件是Pivot
,只有少量數據。在透視項目中是包含TestItems的ListViews。我想通過IsRead屬性篩選一個列表中的項目。是否有可能過濾主要收藏而不保留2個收藏?如果我知道的話,CollectionViewSource
不支持在通用應用上過濾排序。但保持(和同步更改)兩個集合看起來不是個好主意。Windows Phone 8.1上的ObservableCollection過濾通用
編輯: 我已經使用了ObservableCollection,因爲項目列表可能會在後臺更新。可能從原始問題中不清楚。
class TestItem : ModelBase
{
private bool isRead;
public bool IsRead
{
get { return isRead; }
set
{
isRead = value;
NotifyPropertyChanged();
}
}
private string name;
public string Name
{
get { return name; }
set
{
name = value;
NotifyPropertyChanged();
}
}
}
class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
Items = new ObservableCollection<TestItem>();
}
public ObservableCollection<TestItem> Items { get; private set; }
public ObservableCollection<TestItem> ItemsRead { get; private set; } // key point
private void RefreshItems()
{
// data manipulation - on both collections?
}
// ...
}
但問題是,該視圖不會通知有關更改。 – Fanda