diff --git a/dev/Repeater/APITests/InspectingDataSourceTests.cs b/dev/Repeater/APITests/InspectingDataSourceTests.cs index c7e1e218f4..1520683207 100644 --- a/dev/Repeater/APITests/InspectingDataSourceTests.cs +++ b/dev/Repeater/APITests/InspectingDataSourceTests.cs @@ -11,6 +11,7 @@ using Windows.Foundation.Collections; using Windows.UI.Xaml.Controls; using Common; +using System; #if USING_TAEF using WEX.TestExecution; @@ -242,7 +243,27 @@ IEnumerator IEnumerable.GetEnumerator() private class WinRTVectorChangedEventArgs : IVectorChangedEventArgs { public CollectionChange CollectionChange { get; private set; } - public uint Index { get; private set; } + + private uint _index; + public uint Index + { + get + { + if (CollectionChange == CollectionChange.Reset) + { + // C++/CX observable collection fails if accessing index + // when the args is for a Reset, so emulating that behavior here. + throw new InvalidOperationException(); + } + + return _index; + } + + private set + { + _index = value; + } + } public WinRTVectorChangedEventArgs(CollectionChange change, int index) { diff --git a/dev/Repeater/InspectingDataSource.cpp b/dev/Repeater/InspectingDataSource.cpp index 2c8a53f2df..efbc7aa7b1 100644 --- a/dev/Repeater/InspectingDataSource.cpp +++ b/dev/Repeater/InspectingDataSource.cpp @@ -195,7 +195,6 @@ void InspectingDataSource::OnVectorChanged( // Also note that we do not access the data - we just add nullptr. We just // need the count. - const auto index = static_cast(e.Index()); winrt::NotifyCollectionChangedAction action{}; int oldStartingIndex = -1; int newStartingIndex = -1; @@ -207,18 +206,18 @@ void InspectingDataSource::OnVectorChanged( { case winrt::Collections::CollectionChange::ItemInserted: action = winrt::NotifyCollectionChangedAction::Add; - newStartingIndex = index; + newStartingIndex = static_cast(e.Index()); newItems.Append(nullptr); break; case winrt::Collections::CollectionChange::ItemRemoved: action = winrt::NotifyCollectionChangedAction::Remove; - oldStartingIndex = index; + oldStartingIndex = static_cast(e.Index()); oldItems.Append(nullptr); break; case winrt::Collections::CollectionChange::ItemChanged: action = winrt::NotifyCollectionChangedAction::Replace; - oldStartingIndex = index; - newStartingIndex = index; + oldStartingIndex = static_cast(e.Index()); + newStartingIndex = oldStartingIndex; newItems.Append(nullptr); oldItems.Append(nullptr); break; @@ -237,4 +236,4 @@ void InspectingDataSource::OnVectorChanged( oldItems, newStartingIndex, oldStartingIndex)); -} \ No newline at end of file +}