Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigationview: Fix init-once of the GlobalDependencyProperty #6762

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
inline 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::set<winrt::NavigationViewItem> m_itemsWithRevokerObjects;

void InvalidateTopNavPrimaryLayout();
// Measure functions for top navigation
Expand Down