Skip to content

Commit

Permalink
Fix issue with TabView crashing in a NavigationCacheMode=Required page (
Browse files Browse the repository at this point in the history
#1482)

* fixes #1245

* incorporated suggestions from reviewers

* removed unnecessary codes

* more suggestion incorporated

* reverting a previous commit

* added const

* added TeaP's suggestion
  • Loading branch information
mdmozibur authored and StephenLPeters committed Oct 30, 2019
1 parent 370c81c commit 6bc3854
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,28 @@ void TabView::OnListViewLoaded(const winrt::IInspectable&, const winrt::RoutedEv
if (auto listView = m_listView.get())
{
// Now that ListView exists, we can start using its Items collection.
auto items = TabItems();
auto numItemsToCopy = static_cast<int>(items.Size());
if (auto lvItems = listView.Items())
if (auto const lvItems = listView.Items())
{
for (int i = 0; i < numItemsToCopy; i++)
if (!listView.ItemsSource())
{
// App put items in our Items collection; copy them over to ListView.Items
lvItems.Append(items.GetAt(i));
// copy the list, because clearing lvItems may also clear TabItems
winrt::IVector<winrt::IInspectable> const itemList{ winrt::single_threaded_vector<winrt::IInspectable>() };

for (auto const item : TabItems())
{
itemList.Append(item);
}

lvItems.Clear();

for (auto const item : itemList)
{
// App put items in our Items collection; copy them over to ListView.Items
if (item)
{
lvItems.Append(item);
}
}
}
TabItems(lvItems);
}
Expand Down

0 comments on commit 6bc3854

Please sign in to comment.