ISupportIncrementalLoading interface

0 out of 8 rated this helpful - Rate this topic

Specifies a calling contract for collection views that support incremental loading.

Syntax


public interface ISupportIncrementalLoading

Attributes

GuidAttribute("7f5ee992-7694-4e6c-a51b-e34bf43de743")
VersionAttribute(NTDDI_WIN8)
WebHostHiddenAttribute()

Members

The ISupportIncrementalLoading interface has these types of members:

Methods

The ISupportIncrementalLoading interface has these methods. It also inherits methods from the Object class.

MethodDescription
LoadMoreItemsAsync Initializes incremental loading from the view.

 

Properties

The ISupportIncrementalLoading interface has these properties.

PropertyAccess typeDescription

HasMoreItems

Read-onlyGets a sentinel value that supports incremental loading implementations.

 

Examples

The following code example demonstrates how to implement this interface. For the complete code listing, see the XAML data Binding sample.


#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 


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

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

Metadata

Windows.winmd

See also

Binding
XAML data Binding sample
Data binding overview

 

 

Build date: 12/4/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.