NavigationView neglects to apply selection indicator in SelectedItem edge-case
Invoke a NavigationViewItem, programmatically set NavigationView.SelectedItem to null, then re-invoke the NavigationViewItem. NavigationViewItem.IsSelected will be true, but the selection indicator will not appear on the left-side of the NavigationViewItem. Once a different NavigationViewItem is invoked, the selection indicator will work as expected for all items.
- Windows 11 23H2
- FluentAvalonia Version 2.2.0
- Avalonia Version 11.2.1
Issue #579 is very similar. While closely rendering this as a duplicate, this issue is on non-nested NavigationView. Either way, the root cause may be the same. The erroneous code path is within AnimateSelectionChanged on this condition:
if ((prevIndicator != nextIndicator) && paneContentGrid != null && prevIndicator != null &&
nextIndicator != null && FAUISettings.AreAnimationsEnabled())
When animations are disabled, the selection indicator works as expected. Additionally, while observing the visual tree with DevTools, it appears the selection indicator is moved to the wrong NavigationViewItem (note it not visible on this item).
In this screenshot, you can see that the Border of the SelectionIndicator is on (seemingly?) the wrong element. This incongruence doesn't always correspond to the item below, sometimes it is the item above. The accent colour is not blue in this application, that is the highlight from DevTools. 'Panel' is positioned as expected on the selected item.
Just to confirm, if animations are disabled there is no issue with the selection indicator, correct?
If that's the case, then the issue is a problem in the Composition Animation system which is out of my hands. I'm already having to work around some things that WinUI has that Avalonia doesn't (specifically ScopedBatch animations, or an alternate method to notify the UI thread when the composition animation finishes) - the code comes directly from WinUI. Unfortunately (and I know this isn't ideal), all I can say right now is either disable animations or just accept the edge cases where it doesn't work quite right.
Just to confirm, if animations are disabled there is no issue with the selection indicator, correct?
Yes, correct.
Unfortunately (and I know this isn't ideal), all I can say right now is either disable animations or just accept the edge cases where it doesn't work quite right.
I see. We've disabled animations for now.