c# - 使用 Linq MVVM 查询 ObservableCollection

标签 c# wpf linq mvvm

我想在我的 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/

相关文章:

c# - Silverlight 4 应用程序卡住而不抛出任何异常

c# - SQL Server 与 MongoDB : Speed test?

c# - 如何排序 List<Point>

.net - GroupBy 来自日期时间变量的日期

c# - 创建一个暂停的触发器

c# - 将 IOrderedEnumerable 转换为 ICollection

WPF 应用程序在第一次 WCF 调用时卡住

c# - 从 View 模型的构造函数调用异步方法

mysql - 尽管异步调用,ADO .NET 仍然阻塞

c# - 尝试导入非托管 dll 时 Pinvoke "System.AccessViolationException"