我想在我的 ObservableCollection 上使用 linq 创建一个查询,但它并没有像 T 尝试的那样真正起作用。
我有一个模型 Entry
,它有 {note, information, isActive}
作为参数。所以我现在只想获取所有 isActive 为真的 Entries
。我不会在我的数据提供者上使用它(一旦数据被加载),因为我需要将每个条目加载到程序中。
所以我考虑在我的条目 ObservableCollection 中覆盖 getter:
public ObservableCollection<Note> _entries { get; set; }
public ObservableCollection<Note> entries
{
get
{
return new ObservableCollection<Note>(from entry in this._entries
where entry.isActive == true
select entry);
}
set { this._entries = value; }
}
但是您可能猜到这行不通。
问候
最佳答案
尝试
get
{
List<Notes> list = _entries.Where(e=>e.isActive).ToList();
return new ObservableCollection<Note>(list) ;
}
关于c# - 使用 Linq MVVM 查询 ObservableCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392342/