Skip to content

Commit 69318b4

Browse files
committed
fix: Make NavigationView Settings item selectable
- Fixes #4809 - in some cases on some Uno targets, the lifecycle events are in such order that causes presenters of dynamically added NavigationViewItems not to be initialized properly. These changes work around this problem when selection indicator is requeste. These changes can be reverted when #4689 is fixed.
1 parent f17770d commit 69318b4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Uno.UI/Microsoft/UI/Xaml/Controls/NavigationView/NavigationViewItemPresenter.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ protected override void OnApplyTemplate()
3939
var navigationViewItem = GetNavigationViewItem();
4040
if (navigationViewItem != null)
4141
{
42+
#if IS_UNO
43+
// TODO: Uno specific: We may be reapplying the template, in which case
44+
// we need to unsubscribe the previous Tapped event handler.
45+
// Can be removed when #4689.
46+
if (m_expandCollapseChevron != null)
47+
{
48+
m_expandCollapseChevron.Tapped -= navigationViewItem.OnExpandCollapseChevronTapped;
49+
}
50+
#endif
51+
4252
var expandCollapseChevron = GetTemplateChild(c_expandCollapseChevron) as Grid;
4353
if (expandCollapseChevron != null)
4454
{
@@ -87,7 +97,19 @@ internal void RotateExpandCollapseChevron(bool isExpanded)
8797

8898
internal UIElement GetSelectionIndicator()
8999
{
90-
return m_helper.GetSelectionIndicator();
100+
#if IS_UNO
101+
// TODO: Uno specific: This is done to ensure that the presenter
102+
// was initialized properly - if helper is not null, but content grid
103+
// is null, it means the presenter was not initialized correctly.
104+
// Can be removed when #4809 is fixed.
105+
if (m_contentGrid == null && m_helper != null)
106+
{
107+
// Reinitialize
108+
OnApplyTemplate();
109+
}
110+
#endif
111+
// m_helper could be null here, if template was not yet applied
112+
return m_helper?.GetSelectionIndicator();
91113
}
92114

93115
protected override bool GoToElementStateCore(string state, bool useTransitions)

0 commit comments

Comments
 (0)