다음을 통해 공유


ISupportIncrementalLoading 인터페이스

정의

증분 로드를 지원하는 컬렉션 뷰에 대한 호출 계약을 지정합니다.

public interface class ISupportIncrementalLoading
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(2136926610, 30356, 20076, 165, 27, 227, 75, 244, 61, 231, 67)]
struct ISupportIncrementalLoading
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(2136926610, 30356, 20076, 165, 27, 227, 75, 244, 61, 231, 67)]
public interface ISupportIncrementalLoading
Public Interface ISupportIncrementalLoading
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

다음 코드 예제에서는이 인터페이스를 구현 하는 방법을 보여 줍니다. 전체 코드 목록은 XAML 데이터 바인딩 샘플을 참조하세요.

#pragma region Overridable methods

        virtual Concurrency::task<Windows::Foundation::Collections::IVector<Platform::Object^>^> LoadMoreItemsOverride(Concurrency::cancellation_token c, unsigned int count)
        {
            return Concurrency::task<Windows::Foundation::Collections::IVector<Platform::Object^>^>(
                [=]() -> Windows::Foundation::Collections::IVector<Platform::Object^>^ {
                    auto items = ref new Platform::Collections::Vector<Platform::Object^>();
                    return items;
            });
        }
        virtual bool HasMoreItemsOverride()
        {
            return false;
        }

#pragma endregion 

        IncrementalLoadingBase()
        {
            _storage = ref new Platform::Collections::Vector<Platform::Object^>();
            _storage->VectorChanged += ref new Windows::Foundation::Collections::VectorChangedEventHandler<Platform::Object^>(this, &IncrementalLoadingBase::_storageVectorChanged);
            _busy = false;
            _isVectorChangedObserved = false;
        }

    public:

        virtual Windows::Foundation::IAsyncOperation<Windows::UI::Xaml::Data::LoadMoreItemsResult>^ LoadMoreItemsAsync(unsigned int count)
        {
            if (_busy)
            {
                throw ref new Platform::FailureException("Only one operation in flight at a time");
            }

            _busy = true;

            return Concurrency::create_async([=](Concurrency::cancellation_token c) {
                return LoadMoreItemsAsync(c, count)
                    .then([=](Windows::UI::Xaml::Data::LoadMoreItemsResult result) -> Windows::UI::Xaml::Data::LoadMoreItemsResult {
                        _busy = false;
                        return result;
                });
            });
        }

        property bool HasMoreItems
        {
            virtual bool get() { return HasMoreItemsOverride(); }
        }

#pragma endregion 
#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 

속성

HasMoreItems

증분 로드 구현을 지원하는 sentinel 값을 가져옵니다.

메서드

LoadMoreItemsAsync(UInt32)

보기에서 증분 로드를 초기화합니다.

적용 대상

추가 정보