Skip to content

Commit

Permalink
Navigationview: Fix init-once of the GlobalDependencyProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Feb 23, 2022
1 parent 6225742 commit 1d60eba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "pch.h"
#include "common.h"
#include <mutex>
#include <thread>

#include "NavigationView.h"
#include "Vector.h"
Expand Down Expand Up @@ -223,15 +221,17 @@ NavigationView::NavigationView()

m_navigationViewItemsFactory = winrt::make_self<NavigationViewItemsFactory>();

std::call_once(s_NavigationViewItemRevokersPropertySet, [this]() {
static const auto s_NavigationViewItemRevokersPropertyInit = []()
{
s_NavigationViewItemRevokersProperty =
InitializeDependencyProperty(
L"NavigationViewItemRevokers",
winrt::name_of<winrt::IInspectable>(),
winrt::name_of<winrt::NavigationViewItem>(),
true /* isAttached */,
nullptr /* defaultValue */);
});
return false;
}();
}

void NavigationView::OnSelectionModelChildrenRequested(const winrt::SelectionModel& selectionModel, const winrt::SelectionModelChildrenRequestedEventArgs& e)
Expand Down Expand Up @@ -3423,7 +3423,7 @@ void NavigationView::ClearNavigationViewItemRevokers(const winrt::NavigationView

void NavigationView::ClearAllNavigationViewItemRevokers()
{
for (auto const nvi : m_itemsWithRevokerObjects)
for (const auto& nvi : m_itemsWithRevokerObjects)
{
nvi.SetValue(s_NavigationViewItemRevokersProperty, nullptr);
}
Expand Down
5 changes: 2 additions & 3 deletions dev/NavigationView/NavigationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,11 @@ class NavigationView :
// displayed by the repeaters in this control. It is used to keep track of the
// revokers for NavigationViewItem events and allows them to get revoked when
// the item gets cleaned up
GlobalDependencyProperty s_NavigationViewItemRevokersProperty{ nullptr };
static GlobalDependencyProperty s_NavigationViewItemRevokersProperty{ nullptr };
void SetNavigationViewItemRevokers(const winrt::NavigationViewItem& nvi);
void ClearNavigationViewItemRevokers(const winrt::NavigationViewItem& nvi);
void ClearAllNavigationViewItemRevokers();
std::set<winrt::NavigationViewItem> m_itemsWithRevokerObjects{};
std::once_flag s_NavigationViewItemRevokersPropertySet;
std::unordered_set<winrt::NavigationViewItem> m_itemsWithRevokerObjects;

void InvalidateTopNavPrimaryLayout();
// Measure functions for top navigation
Expand Down
1 change: 1 addition & 0 deletions dev/dll/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

// STL
#include <vector>
#include <unordered_set>
#include <map>
#include <functional>

Expand Down

0 comments on commit 1d60eba

Please sign in to comment.