增量加载和捕捉视觉状态 [英] Incremental Loading and snapped visual state

查看:122
本文介绍了增量加载和捕捉视觉状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序页面(它是项目页面模板)中有一个listview(用于捕捉状态)和一个gridview(用于常规状态),并且它们都绑定到一个集合, code> ISupportIncrementalLoading 接口。这里是实现的方法:

I have a listview(for snapped state) and a gridview(for normal state) in my app page (which is an items page template) and they are both bound to a collection that implements ISupportIncrementalLoading interface. Here are the implemented methods:

public HasMoreItemsDelegate MoreItemsExist { get; set; }
        public LoadMoreItemsDelegate<T> ItemsLoadAsync { get; set; }

        public bool HasMoreItems
        {
            get 
            {
                return this.MoreItemsExist();
            }
        }

        private bool isLoading;

        public bool IsLoading
        {
            get
            {
                return this.isLoading;
            }
            private set
            {
                this.isLoading = value;
                this.OnPropertyChanged("IsLoading");
            }
        }

        public Windows.Foundation.IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            if (this.IsLoading)
            {
               throw new InvalidOperationException("Only one operation in flight at a time");
            }
            this.IsLoading = true;
            return AsyncInfo.Run((c) => LoadMoreItemsAsync(c, count));
        }

        async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
        {
            try
            {
                IEnumerable<T> itemsToAdd = await ItemsLoadAsync(c, count);
                foreach (var item in itemsToAdd)
                {
                    this.Add(item);
                }
                return new LoadMoreItemsResult { Count = (uint)itemsToAdd.Count() };
            }
            finally
            {
                this.IsLoading = false;
            }
        }

我遇到的问题是:当应用程序处于捕捉模式,并使用listview和gridview导航到页面,BOTH视图尝试调用 LoadMoreItemsAsync ,并且我输入了异常子句,而在正常(全屏)模式下, gridview调用方法,而listview不会。

The problem I encounter is: When the app is in snapped mode and I navigate to the page with the listview and gridview, BOTH views try to call LoadMoreItemsAsync and I enter the exception clause, whereas when in normal (fullscreen) mode, only the gridview calls the method, and the listview doesn't.

推荐答案

问题出在模板的工作方式上。 gridview默认是可见的,而listview不是。当我们导航到页面时, VisualStateManager 被称为 AFTER ,页面被渲染,因此当浏览到时,gridview对于短片并在隐藏之前调用 LoadMoreItemsAsync 方法。故事板完成后,listview会显示出来,并且还会调用 LoadMoreItemsAsync 并出现问题。

The problem comes from how the template works. The gridview is Visible by default and the listview is not. When we navigate to the page, the VisualStateManager is called AFTER the page is rendered, and therefore when navigated to, the gridview is visible for a short time and calls the LoadMoreItemsAsync method before it gets hidden. After the storyboard is complete, the listview gets shown and also calls the LoadMoreItemsAsync and the problem occurs.

我如何解决了这个问题:制作了两个视图默认情况下折叠并在 VisualStateManager 中显示时处理(它总是在导航到页面后调用)。

How I solved it: Made both views Collapsed by default and handled when they are shown in the VisualStateManager (it's ALWAYS called after navigating to the page).

这篇关于增量加载和捕捉视觉状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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