[UWP] ListViews在更新数据时崩溃应用程序 [英] [UWP] ListViews crashing app when data is updated

查看:154
本文介绍了[UWP] ListViews在更新数据时崩溃应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的应用程序在概念上有问题(我不认为这是代码问题)。

I think I have something conceptually wrong with my app (I don't think it's a code issue).

我有一个带有ListView的页面。 ItemsSource绑定到存储在my((App)Application.Current中的数据模型)。如果我在更新数据时导航到ListView页面,应用程序会在新数据填充ListView时崩溃(您可以看到数据开始更改,然后应用程序崩溃。如果我提供数据在导航到列表页面之前更新时间一切正常,新数据显示在ListView中。

I have a page with a ListView. The ItemsSource is bound to a data model stored in my ((App)Application.Current). If I navigate to the ListView page while the data is being updated, the app crashes as the moment the new data populates the ListView (you can see the data start to change, then the app crashes. If I give the data time to update before navigating to the list page everything is fine, and the new data is shown in the ListView.

我得到的例外情况我通常会发现这是一个XAML问题:

The exception I get takes me to this, which I usually find is a XAML problem:

#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
#endif

'e'告诉我'价值不在预期范围内',但我不知道有什么价值。看看我的数据模型我的所有数据都填充/非空。

'e' tells me 'Value does not fall within the expected range', but I have no idea what value. Looking at my data model all my data is populated / non-null.

数据本身从各种Web源异步下载。问题是否可能是由于在显示ListView时异步更新数据(可能是在单独的线程上)?我是否需要更改更新数据的方式?

The data itself is downloaded asynchronously from various web sources. Is the problem possibly caused by updating the data asynchronously while displaying the ListView (presumably on separate threads)? Do I need to change the way I update my data?

访问http://blog.grogansoft.com/进行Windows开发。

Visit http://blog.grogansoft.com/ for Windows development fun.

推荐答案

Hello pumpkinszwan,

Hello pumpkinszwan,

>>问题可能是由于在显示时异步更新数据引起的ListView(大概是在单独的线程上)?

>>Is the problem possibly caused by updating the data asynchronously while displaying the ListView (presumably on separate threads)?

我同意这可能是问题所在。由于它在您的数据更新时有效。

I agree that might be the problem. Since it works when your data updated.

如何考虑使用虚拟化而不是同时加载所有项目?

How about consider using the virtualization instead of load all items at the same time?

请参见:

ListView和GridView数据虚拟化

如果只显示几个项目,导航到应用程序时应用程序是否会崩溃?

If only shows a few items, will the app still crash when you navigate to it?

祝你好运,

Barry


这篇关于[UWP] ListViews在更新数据时崩溃应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆