Skip to content

Commit

Permalink
Transfer changes from microsoft#1395
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelwgn committed Feb 8, 2020
1 parent de7bc2a commit 4062667
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
27 changes: 23 additions & 4 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,12 @@ void NavigationView::CreateAndHookEventsToSettings(std::wstring_view settingsNam
bool shouldSelectSetting = selectedItem && IsSettingsItem(selectedItem);

if (shouldSelectSetting)
{
{
auto scopeGuard = gsl::finally([this]()
{
m_shouldIgnoreNextSelectionChange = false;
});
m_shouldIgnoreNextSelectionChange = true;
SetSelectedItemAndExpectItemInvokeWhenSelectionChangedIfNotInvokedFromAPI(nullptr);
}

Expand Down Expand Up @@ -806,7 +811,12 @@ void NavigationView::CreateAndHookEventsToSettings(std::wstring_view settingsNam
SetValue(s_SettingsItemProperty, settingsItem);

if (shouldSelectSetting)
{
{
auto scopeGuard = gsl::finally([this]()
{
m_shouldIgnoreNextSelectionChange = false;
});
m_shouldIgnoreNextSelectionChange = true;
SetSelectedItemAndExpectItemInvokeWhenSelectionChangedIfNotInvokedFromAPI(m_settingsItem.get());
}
}
Expand Down Expand Up @@ -2265,8 +2275,18 @@ void NavigationView::UpdateSingleSelectionFollowsFocusTemplateSetting()
void NavigationView::OnSelectedItemPropertyChanged(winrt::DependencyPropertyChangedEventArgs const& args)
{
auto newItem = args.NewValue();
auto oldItem = args.OldValue();

ChangeSelection(args.OldValue(), newItem);
ChangeSelection(oldItem, newItem);

// Animate to be sure the selected item is visually higlighted!
// See #1395 for additional context
if (oldItem != newItem)
{
ChangeSelectStatusForItem(oldItem, false /*selected*/);
ChangeSelectStatusForItem(newItem, true /*selected*/);
AnimateSelectionChanged(oldItem, newItem);
}

if (m_appliedTemplate && IsTopNavigationView())
{
Expand Down Expand Up @@ -2306,7 +2326,6 @@ void NavigationView::SetSelectedItemAndExpectItemInvokeWhenSelectionChangedIfNot

m_indexOfLastSelectedItemInTopNav = m_topDataProvider.IndexOf(item); // for the next time we animate
}

SelectedItem(item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,41 @@ public void KeyboardFocusToolTipTest() // Verify tooltips appear when Keyboard f
}
}

[TestMethod]
[TestProperty("TestSuite", "C")]
public void DisplayModeChangeSelectionEventTest()
{
var testScenarios = RegressionTestScenario.BuildLeftNavRegressionTestScenarios();
foreach (var testScenario in testScenarios)
{
using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "NavigationView Test" }))
{
if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone3))
{
Log.Warning("Test is disabled on RS2 and earlier because SplitView lacks the requisite events.");
return;
}
Button clearSelectedItem = new Button(FindElement.ById("ClearSelectionChangeIndicatorButton"));
TextBlock selectionRaisedIndicator = new TextBlock(FindElement.ById("SelectionChangedRaised"));

ComboBox selectedItem = new ComboBox(FindElement.ById("SelectedItemCombobox"));
selectedItem.SelectItemByName("Settings");
Verify.AreEqual("True", selectionRaisedIndicator.GetText());

ComboBox displayMode = new ComboBox(FindElement.ById("PaneDisplayModeCombobox"));
clearSelectedItem.InvokeAndWait();
displayMode.SelectItemByName("Top");
Verify.AreEqual("False", selectionRaisedIndicator.GetText());
Wait.ForIdle();


displayMode.SelectItemByName("Left");
Wait.ForIdle();
Verify.AreEqual("False", selectionRaisedIndicator.GetText());
}
}
}

[TestMethod]
[TestProperty("TestSuite", "C")]
public void PaneOpenCloseEventsTest()
Expand Down
3 changes: 3 additions & 0 deletions dev/NavigationView/TestUI/NavigationViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@
<ComboBoxItem Content="LeftCompact" Tag="LeftCompact"/>
<ComboBoxItem Content="LeftMinimal" Tag="LeftMinimal"/>
</ComboBox>
<Button x:Name="ClearSelectionChangeIndicatorButton" AutomationProperties.Name="ClearSelectionChangeIndicatorButton" Click="ClearSelectionChangeBlock">Clear selection changed indicator</Button>
<TextBlock VerticalAlignment="Center">Selection was raised: </TextBlock>
<TextBlock VerticalAlignment="Center" x:Name="SelectionChangedRaised" AutomationProperties.Name="SelectionChangedRaised"/>
</StackPanel>

<StackPanel Orientation="Horizontal">
Expand Down
6 changes: 6 additions & 0 deletions dev/NavigationView/TestUI/NavigationViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvoke

private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
SelectionChangedRaised.Text = "True";
// Reset argument type indicatiors
SelectionChangedItemType.Text = "null";
SelectionChangedItemContainerType.Text = "null";
Expand Down Expand Up @@ -380,6 +381,11 @@ private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelec
}
}

private void ClearSelectionChangeBlock(object sender,RoutedEventArgs e)
{
SelectionChangedRaised.Text = "False";
}

private void MoviesEnabledCheckbox_Checked(object sender, RoutedEventArgs e)
{
MoviesItem.IsEnabled = true;
Expand Down

0 comments on commit 4062667

Please sign in to comment.