Skip to content

Commit

Permalink
NavigationView not updating UIA users about changed selection and exp…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Jul 14, 2020
1 parent 4c910a2 commit 8728abb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
33 changes: 33 additions & 0 deletions ModernWpf.Controls/NavigationView/NavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,12 @@ internal void OnNavigationViewItemInvoked(NavigationViewItem nvi)
if (updateSelection)
{
var ip = GetIndexPathForContainer(nvi);

// Determine if we will update collapse/expand which will happen iff the item has children
if (DoesNavigationViewItemHaveChildren(nvi))
{
m_shouldIgnoreUIASelectionRaiseAsExpandCollapseWillRaise = true;
}
UpdateSelectionModelSelection(ip);
}

Expand Down Expand Up @@ -2133,6 +2139,31 @@ NavigationRecommendedTransitionDirection init()
UnselectPrevItem(prevItem, nextItem);
ChangeSelectStatusForItem(nextItem, true /*selected*/);

try
{
// Selection changed and we need to notify UIA
// HOWEVER expand collapse can also trigger if an item can expand/collapse
// There are multiple cases when selection changes:
// - Through click on item with no children -> No expand/collapse change
// - Through click on item with children -> Expand/collapse change
// - Through API with item without children -> No expand/collapse change
// - Through API with item with children -> No expand/collapse change
if (!m_shouldIgnoreUIASelectionRaiseAsExpandCollapseWillRaise)
{
if (FrameworkElementAutomationPeer.FromElement(this) is AutomationPeer peer)
{
var navViewItemPeer = (NavigationViewAutomationPeer)peer;
navViewItemPeer.RaiseSelectionChangedEvent(
prevItem, nextItem
);
}
}
}
finally
{
m_shouldIgnoreUIASelectionRaiseAsExpandCollapseWillRaise = false;
}

RaiseSelectionChangedEvent(nextItem, isSettingsItem, recommendedDirection);
AnimateSelectionChanged(nextItem);

Expand Down Expand Up @@ -5314,6 +5345,8 @@ protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)

bool m_moveTopNavOverflowItemOnFlyoutClose = false;

bool m_shouldIgnoreUIASelectionRaiseAsExpandCollapseWillRaise = false;

FocusHelper m_leftNavRepeaterFocusHelper;
FocusHelper m_topNavRepeaterFocusHelper;

Expand Down
17 changes: 17 additions & 0 deletions ModernWpf.Controls/NavigationView/NavigationViewAutomationPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,22 @@ public IRawElementProviderSimple[] GetSelection()
}
return new IRawElementProviderSimple[0];
}

internal void RaiseSelectionChangedEvent(object oldSelection, object newSelecttion)
{
if (AutomationPeer.ListenerExists(AutomationEvents.SelectionPatternOnInvalidated))
{
if (Owner is NavigationView nv)
{
if (nv.GetSelectedContainer() is { } nvi)
{
if (FrameworkElementAutomationPeer.CreatePeerForElement(nvi) is { } peer)
{
peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
}
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions ModernWpf.Controls/NavigationView/NavigationViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Specialized;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -280,6 +281,19 @@ void SuggestedToolTipChanged(object newContent)
m_suggestedToolTipContent = newToolTipContent;
}

void OnIsExpandedPropertyChanged(DependencyPropertyChangedEventArgs args)
{
if (FrameworkElementAutomationPeer.FromElement(this) is AutomationPeer peer)
{
var navViewItemPeer = (NavigationViewItemAutomationPeer)peer;
navViewItemPeer.RaiseExpandCollapseAutomationEvent(
IsExpanded ?
ExpandCollapseState.Expanded :
ExpandCollapseState.Collapsed
);
}
}

void OnIconPropertyChanged(DependencyPropertyChangedEventArgs args)
{
UpdateVisualStateNoTransition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ public bool IsExpanded

private static void OnIsExpandedPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
((NavigationViewItem)sender).OnIsExpandedPropertyChanged(args);
}

private void OnIsExpandedPropertyChanged(DependencyPropertyChangedEventArgs args)
{
IsExpandedChanged?.Invoke(this, args.Property);
var owner = (NavigationViewItem)sender;
owner.OnIsExpandedPropertyChanged(args);
owner.IsExpandedChanged?.Invoke(owner, args.Property);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void IExpandCollapseProvider.Expand()
}
}

void RaiseExpandCollapseAutomationEvent(ExpandCollapseState newState)
internal void RaiseExpandCollapseAutomationEvent(ExpandCollapseState newState)
{
if (AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged))
{
Expand Down

0 comments on commit 8728abb

Please sign in to comment.