Repository navigation
Description
Current behavior
In UWP, the NavigationVIewItem.SetNavigationViewParent method is called before OnApplyTemplate, which is needed to properly initialize the items and NavigationVIewItemPresenters. The SetNavigationViewParent is called from OnRepeaterElementPrepared handler, which unfortunately runs after item's OnApplyTemplate executes in Uno (reproduced on Android, WASM, Skia, probably happens on others too). In addition, I noticed that when I run the HierarchicalNavigationViewMarkup test page (in NavigationView section of samples app), an assert fails in VirtualizationInfo.MoveOwnershipToLayoutFromElementFactory, maybe it is related somehow. Currently I have worked around the SetNavigationViewParent problem by walking up the Visual tree (see the NavigationViewItemBase.FindAncestorNavigationView method), but that does help on Skia and WASM only, whereas on Android and iOS, the parent is not yet set when OnApplyTemplate is called.
The problem is likely related to the lifetime events order.
Expected behavior
OnElementPrepared should be called before OnApplyTemplate.
How to reproduce it (as minimally and precisely as possible)
See above.
Workaround
Currently worked around in ItemsRepeater and NavigationView source.
Environment
Nuget Package:
- Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
- Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
- Uno.SourceGenerationTasks
- Uno.UI.RemoteControl / Uno.WinUI.RemoteControl
- Other:
Nuget Package Version(s):
Affected platform(s):
- iOS
- Android
- WebAssembly
- WebAssembly renderers for Xamarin.Forms
- macOS
- Skia
- WPF
- GTK (Linux)
- Tizen
- Windows
- Build tasks
- Solution Templates
IDE:
- Visual Studio 2017 (version: )
- Visual Studio 2019 (version: )
- Visual Studio for Mac (version: )
- Rider Windows (version: )
- Rider macOS (version: )
- Visual Studio Code (version: )
Relevant plugins:
- Resharper (version: )
Activity
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
chore(NavigationView): NavigationViewItem workarounds
MartinZikmund commentedon Dec 30, 2020
The
OnApplyTemplateorder has effects onNavigationViewPresenteras well (which is nested in theNavigationViewItem)fix: Make NavigationView Settings item selectable
9 remaining items
NavigationView#21054MartinZikmund commentedon Jul 28, 2025
Likely fixed for Skia, but needs to be verified
test: Reproduce ItemsRepeater ElementPrepared ordering vs OnApplyTemp…
MartinZikmund commentedon Apr 8, 2026
Repro generator
Runtime test(s) added in branch
dev/mazi/repro/4689:src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater.cs→When_ElementPrepared_Then_FiredBeforeOnApplyTemplateElementPreparedfires beforeOnApplyTemplatefor elements in anItemsRepeater, using a customContentControlsubclass that tracks event ordering. On the current Skia target, the ordering is correct (ElementPrepared first, then OnApplyTemplate).Note: The original issue was specifically about
NavigationViewIteminsideNavigationView's internal repeater. The test uses a simpler standaloneItemsRepeaterscenario — the NavigationView-specific interaction may still have edge cases not covered by this test.refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds
refactor(radiobuttons): Remove obsolete Uno workarounds