ISupportIncrementalLoading Interface

指定支持增量加载的集合视图的调用协定。

语法


public interface ISupportIncrementalLoading

特性

[Version(0x06020000)]
[WebHostHidden()]

成员

ISupportIncrementalLoading接口 具有这些类型的成员:

方法

The ISupportIncrementalLoading 接口 具有这些方法。 它还继承方法于Object 类.

方法说明
LoadMoreItemsAsync Initializes incremental loading from the view.

 

属性

ISupportIncrementalLoading接口 具有这些属性。

属性访问类型说明

HasMoreItems

只读Gets a sentinel value that supports incremental loading implementations.

 

示例

下面的代码示例演示如何实现此接口。有关完整的代码列表,请参见 XAML 数据绑定示例


#region ISupportIncrementalLoading

public bool HasMoreItems
{
    get { return HasMoreItemsOverride(); }
}

public Windows.Foundation.IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
    if (_busy)
    {
        throw new InvalidOperationException("Only one operation in flight at a time");
    }

    _busy = true;

    return AsyncInfo.Run((c) => LoadMoreItemsAsync(c, count));
}

#endregion 

#region INotifyCollectionChanged

public event NotifyCollectionChangedEventHandler CollectionChanged;

#endregion 

#region Private methods

async Task<LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count)
{
    try
    {
        var items = await LoadMoreItemsOverrideAsync(c, count);
        var baseIndex = _storage.Count;

        _storage.AddRange(items);

        // Now notify of the new items
        NotifyOfInsertedItems(baseIndex, items.Count);

        return new LoadMoreItemsResult { Count = (uint)items.Count };
    }
    finally
    {
        _busy = false;
    }
}

void NotifyOfInsertedItems(int baseIndex, int count)
{
    if (CollectionChanged == null)
    {
        return;
    }

    for (int i = 0; i < count; i++)
    {
        var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, _storage[i + baseIndex], i + baseIndex);
        CollectionChanged(this, args);
    }
}

#endregion

#region Overridable methods

protected abstract Task<IList<object>> LoadMoreItemsOverrideAsync(CancellationToken c, uint count);
protected abstract bool HasMoreItemsOverride();

#endregion 

#region State

List<object> _storage = new List<object>();
bool _busy = false;

#endregion 


要求

最低支持客户端

Windows 8

最低支持服务器

Windows Server 2012

命名空间

Windows.UI.Xaml.Data
Windows::UI::Xaml::Data [C++]

元数据

Windows.winmd

另请参见

Binding
XAML 数据绑定示例
数据绑定概述

 

 

显示:
© 2014 Microsoft