【问题标题】:Incremental loading with progress ring带进度环的增量加载
【发布时间】:2016-04-20 10:11:32
【问题描述】:

我在我的应用程序中实现了增量加载,它有isLoading bool 变量,当hasMoreItems 设置为false 时,它​​在构造函数中设置为true 并设置为false。我有ProgressRing,它的工作原理是这样的:

private void List_LayoutUpdated(object sender, object e)
{
    if (list.Items.Count == 0 && list.ItemsSource == null)
        CenterProgressRing.IsActive = true;
    else if (list.Items.Count == 0 && list.ItemsSource != null) 
    {
        if (!((IncrementalSource)this.list.ItemsSource).isLoading)
            CenterProgressRing.IsActive = false; 
        else CenterProgressRing.IsActive = true;
    }
    else CenterProgressRing.IsActive = false;        
}

所以它在第一页加载时显示ProgressRing,当有物品要接收时它工作得很好。但是当涉及到没有东西可以加载的情况时,ProgressRing 会一直保持活跃状态​​。我不知道为什么。

【问题讨论】:

    标签: c# progress-bar lazy-loading


    【解决方案1】:

    首先,简化您的条件(删除嵌套和否定)。

    if (list.ItemsSource == null)
    {
        CenterProgressRing.IsActive = false;
        return;
    }
    CenterProgressRing.IsActive = ((IncrementalSource)this.list.ItemsSource).isLoading;
    

    如果在你的最后一个项目下载后没有调用List_LayoutUpdated,它可能不起作用(因为布局没有更新)。可能,您可以在 IncrementalSource 中更新 CenterProgressRing.IsActive(如果您实现事件或使 isLoading 可观察)或确保在下载最后一个项目后 List_LayoutUpdated。

    【讨论】:

    • 你说对了List_LayoutUpdated 在下载最后一个项目后没有被调用。使isLoading 可观察也无济于事。但是按照this post 中的建议添加动作/事件就可以了。无论如何,感谢您的贡献,我会将您的答案标记为已接受的答案。
    猜你喜欢
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    相关资源
    最近更新 更多