You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI中IEnumerable转ObservableCollection时RefreshView停止加载的原因?

问题描述

我尝试了以下两种方案,但问题依旧。我清楚转换过程需要耗时,但至少不要让RefreshView停止加载。

方案1

Users = new ObservableCollection<User>(users);

方案2

private async Task LoadUsers()
{
    // some code here

    Users = users.ToObservableCollection();
    OnPropertyChanged(nameof(Users));

    // some code here
}

public static class EnumerableExtension
{
    public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> source)
    {
        ObservableCollection<T> collection = new ObservableCollection<T>();
        foreach (T item in source) collection.Add(item);
        return collection;
    }
}

内容的提问来源于stack exchange,提问作者dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 19:58:08