File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
NavigationView_InteractionTests Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ winrt::hstring NavigationViewItemAutomationPeer::GetNameCore()
4646
4747winrt::IInspectable NavigationViewItemAutomationPeer::GetPatternCore (winrt::PatternInterface const & pattern)
4848{
49+ // Note: We are intentionally not supporting Invoke Pattern, since supporting both SelectionItem and Invoke was
50+ // causing problems.
51+ // See this Issue for more details: https://github.com/microsoft/microsoft-ui-xaml/issues/2702
4952 if (pattern == winrt::PatternInterface::SelectionItem ||
5053 // Only provide expand collapse pattern if we have children!
5154 (pattern == winrt::PatternInterface::ExpandCollapse && HasChildren ()))
@@ -365,6 +368,11 @@ void NavigationViewItemAutomationPeer::RemoveFromSelection()
365368
366369void NavigationViewItemAutomationPeer::ChangeSelection (bool isSelected)
367370{
371+ // If the item is being selected, we trigger an invoke as if the user had clicked on the item:
372+ if (isSelected)
373+ {
374+ Invoke ();
375+ }
368376 if (auto nvi = Owner ().try_as <winrt::NavigationViewItem>())
369377 {
370378 nvi.IsSelected (isSelected);
Original file line number Diff line number Diff line change @@ -350,6 +350,28 @@ public void VerifySelectedItemInInvokedItem()
350350 Verify . AreEqual ( "ItemWasInvokedSecomdTimeWithCorrectSelection" , result . GetText ( ) ) ;
351351 }
352352 }
353+
354+ [ TestMethod ]
355+ public void VerifySelectionItemPatternDoesInvoke ( )
356+ {
357+ // When using UIA SelectionItem pattern to select a navview item, this should also trigger an
358+ // invoke on the item.
359+ using ( var setup = new TestSetupHelper ( new [ ] { "NavigationView Tests" , "NavigationView Test" } ) )
360+ {
361+ var musicItem = FindElement . ByName ( "Music" ) ;
362+ var lvi = new ListViewItem ( musicItem ) ;
363+
364+ lvi . Select ( ) ;
365+ Wait . ForIdle ( ) ;
366+
367+ Log . Comment ( "Verify item was invoked" ) ;
368+ var result = new TextBlock ( FindElement . ByName ( "InvokedItemState" ) ) ;
369+ Verify . AreEqual ( "ItemWasSelectedInItemInvoked" , result . GetText ( ) ) ;
370+
371+ Log . Comment ( "Verify item got selected" ) ;
372+ Verify . IsTrue ( Convert . ToBoolean ( musicItem . GetProperty ( UIProperty . Get ( "SelectionItem.IsSelected" ) ) ) ) ;
373+ }
374+ }
353375
354376 [ TestMethod ]
355377 public void VerifyNavigationViewItemIsSelectedWorks ( )
You can’t perform that action at this time.
0 commit comments