From fd69463ae983b357f00a98ba96ffe9573f04174f Mon Sep 17 00:00:00 2001 From: chinboy Date: Tue, 28 Jul 2026 16:31:03 +0800 Subject: [PATCH] feat(Menu): add toggle for enabling popup scrolling in menu showcase --- .../Navigation/Menu/Localization/en_US.cs | 1 + .../Navigation/Menu/Localization/zh_CN.cs | 1 + .../Navigation/Menu/Localization/zh_TW.cs | 1 + .../Menu/ViewModels/MenuViewModel.cs | 8 +++ .../Navigation/Menu/Views/MenuShowCase.axaml | 63 +++++++------------ .../ShowCases/MenuShowCaseExamples.snapshot | 2 +- .../ShowCases/MenuShowCasePageTests.cs | 33 +++++++++- 7 files changed, 67 insertions(+), 42 deletions(-) diff --git a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/en_US.cs b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/en_US.cs index d821e2323..ceb557222 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/en_US.cs +++ b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/en_US.cs @@ -70,6 +70,7 @@ internal partial class en_US public const string P2HeaderDisabled = "Disabled"; public const string P2HeaderMenu = "_Menu"; public const string P2HeaderMenuItem = "Menu Item"; + public const string P2TextEnablePopupScroll = "Enable popup scrolling"; public const string P2TextRightClickToShowContextMenu = "Right Click to show Context Menu"; public const string P2TitleNormal = "Normal"; public const string P2TextRightClickToShowContextFlyout = "Right Click to show Context Flyout"; diff --git a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_CN.cs b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_CN.cs index 2629803b2..a6e661ab1 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_CN.cs +++ b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_CN.cs @@ -70,6 +70,7 @@ internal partial class zh_CN public const string P2HeaderDisabled = "禁用"; public const string P2HeaderMenu = "_菜单"; public const string P2HeaderMenuItem = "菜单项"; + public const string P2TextEnablePopupScroll = "开启弹层滚动"; public const string P2TextRightClickToShowContextMenu = "右键显示上下文菜单"; public const string P2TitleNormal = "普通"; public const string P2TextRightClickToShowContextFlyout = "右键显示上下文浮出层"; diff --git a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_TW.cs b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_TW.cs index 4bc0c7e2f..d006b8499 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_TW.cs +++ b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_TW.cs @@ -70,6 +70,7 @@ internal partial class zh_TW public const string P2HeaderDisabled = "禁用"; public const string P2HeaderMenu = "_菜單"; public const string P2HeaderMenuItem = "菜單項"; + public const string P2TextEnablePopupScroll = "開啟彈層滾動"; public const string P2TextRightClickToShowContextMenu = "右鍵顯示上下文菜單"; public const string P2TitleNormal = "普通"; public const string P2TextRightClickToShowContextFlyout = "右鍵顯示上下文浮出層"; diff --git a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/ViewModels/MenuViewModel.cs b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/ViewModels/MenuViewModel.cs index 0bbb37b40..b706e9143 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/ViewModels/MenuViewModel.cs +++ b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/ViewModels/MenuViewModel.cs @@ -53,6 +53,14 @@ public class MenuViewModel : ReactiveObject, IRoutableViewModel, IActivatableVie set => this.RaiseAndSetIfChanged(ref _isDark, value); } + private bool _isPopupScrollEnabled = true; + + public bool IsPopupScrollEnabled + { + get => _isPopupScrollEnabled; + set => this.RaiseAndSetIfChanged(ref _isPopupScrollEnabled, value); + } + private NavMenuMode _mode = NavMenuMode.Inline; public NavMenuMode Mode diff --git a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Views/MenuShowCase.axaml b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Views/MenuShowCase.axaml index 148e406f7..7f7712e75 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Views/MenuShowCase.axaml +++ b/controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Views/MenuShowCase.axaml @@ -119,46 +119,29 @@ IsDeferredContentEnabled="True"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/AtomUIGallery.Tests/ShowCases/MenuShowCaseExamples.snapshot b/tests/AtomUIGallery.Tests/ShowCases/MenuShowCaseExamples.snapshot index 94a46c4f9..2436d5f02 100644 --- a/tests/AtomUIGallery.Tests/ShowCases/MenuShowCaseExamples.snapshot +++ b/tests/AtomUIGallery.Tests/ShowCases/MenuShowCaseExamples.snapshot @@ -1,2 +1,2 @@ count: 16 -sha256: a173e1bc38a221b03d379f69d49b35174135a72dc9272ea5b1b926c7f3b0d719 +sha256: dcb660af0fb4c2075469b494a7cf8f6131c081bf6520be9870d19720a4107f8d diff --git a/tests/AtomUIGallery.Tests/ShowCases/MenuShowCasePageTests.cs b/tests/AtomUIGallery.Tests/ShowCases/MenuShowCasePageTests.cs index d45d36c53..27c310d2b 100644 --- a/tests/AtomUIGallery.Tests/ShowCases/MenuShowCasePageTests.cs +++ b/tests/AtomUIGallery.Tests/ShowCases/MenuShowCasePageTests.cs @@ -121,6 +121,32 @@ public class MenuShowCasePageTests viewModel.LastCommandKey.ShouldBe("customer-overview"); } + [Fact] + public void Menu_ShowCase_Scrollable_Menu_Can_Toggle_Popup_Scrolling() + { + var pageSource = ReadRepoFile("controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Views/MenuShowCase.axaml"); + var viewModelSource = ReadRepoFile("controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/ViewModels/MenuViewModel.cs"); + var zhCN = ReadRepoFile("controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_CN.cs"); + var zhTW = ReadRepoFile("controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/zh_TW.cs"); + var enUS = ReadRepoFile("controlgallery/AtomUIGallery/ShowCases/Navigation/Menu/Localization/en_US.cs"); + var scrollableShowCaseSource = ExtractShowCaseItem(pageSource, "ScrollableTitle"); + + scrollableShowCaseSource.ShouldContain("MenuShowCaseLangResource ScrollableTitle"); + scrollableShowCaseSource.ShouldContain("MenuShowCaseLangResource P2TextEnablePopupScroll"); + scrollableShowCaseSource.ShouldContain("IsChecked=\"{Binding IsPopupScrollEnabled}\""); + scrollableShowCaseSource.ShouldContain("IsScrollEnabled=\"{Binding IsPopupScrollEnabled}\""); + scrollableShowCaseSource.ShouldNotContain("IsCheckedChanged=\""); + CountOccurrences(scrollableShowCaseSource, "Header=\"{gallery:MenuShowCaseLangResource P2HeaderMenuItem}\"") + .ShouldBe(12); + + viewModelSource.ShouldContain("private bool _isPopupScrollEnabled = true;"); + viewModelSource.ShouldContain("public bool IsPopupScrollEnabled"); + + zhCN.ShouldContain("public const string P2TextEnablePopupScroll = \"开启弹层滚动\";"); + zhTW.ShouldContain("public const string P2TextEnablePopupScroll = \"開啟彈層滾動\";"); + enUS.ShouldContain("public const string P2TextEnablePopupScroll = \"Enable popup scrolling\";"); + } + [Fact] public void Menu_ShowCase_Examples_Match_Approved_Control_Demo_Content() { @@ -161,10 +187,15 @@ public class MenuShowCasePageTests } private static string ExtractNavMenuNodeCommandShowCaseItem(string source) + { + return ExtractShowCaseItem(source, "NavMenuNodeCommandTitle"); + } + + private static string ExtractShowCaseItem(string source, string titleResourceName) { var match = Regex.Match( source, - @"", + $@"", RegexOptions.CultureInvariant | RegexOptions.Singleline); match.Success.ShouldBeTrue();