From c87ef671034987df7fad0f7a1bbf9a5e40878f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pol=C3=A1=C5=A1ek?= Date: Tue, 21 Jul 2026 17:29:03 +0200 Subject: [PATCH] CmdPal: Ensure visual state groups set properties exclusively (#49319) ## Summary of the Pull Request This PR updates DockItemControl to ensure that visual state groups exclusively set properties and don't overlap to prevent unexpected and undeterministic result. - TextVisibilityStates and TextAlignmentStates shared SubtitleText.Visibility - TextVisibilityStates and IconVisibilityStates shared ContentGrid.ColumnSpacing ## PR Checklist - [x] Closes: #47980 - [x] Closes: #49156 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- .../Dock/DockItemControl.xaml | 27 ++++++++++++------- .../Dock/DockItemControl.xaml.cs | 17 +++++++++++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml index fd0c705e7d..260239e9ef 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml @@ -152,11 +152,7 @@ - - - - - + @@ -165,21 +161,35 @@ - + + + + + + + + - + + + + + + + + @@ -199,7 +209,6 @@ - @@ -211,4 +220,4 @@ - \ No newline at end of file + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml.cs index 41af183c3c..819a720043 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockItemControl.xaml.cs @@ -104,6 +104,7 @@ public sealed partial class DockItemControl : Control private void UpdateCompactState() { VisualStateManager.GoToState(this, IsCompact ? "Compact" : "DefaultLayout", true); + UpdateSubtitleVisibilityState(); } private const string IconPresenterName = "IconPresenter"; @@ -120,7 +121,6 @@ public sealed partial class DockItemControl : Control { control.UpdateTextVisibility(); control.UpdateAlignment(); - control.UpdateCompactState(); } } @@ -142,6 +142,8 @@ public sealed partial class DockItemControl : Control private void UpdateTextVisibility() { UpdateTextVisibilityState(); + UpdateSubtitleVisibilityState(); + UpdateContentSpacingState(); } private void UpdateTextVisibilityState() @@ -166,6 +168,12 @@ public sealed partial class DockItemControl : Control VisualStateManager.GoToState(this, stateName, true); } + private void UpdateSubtitleVisibilityState() + { + var showSubtitle = HasSubtitle && !IsCompact; + VisualStateManager.GoToState(this, showSubtitle ? "SubtitleVisible" : "SubtitleHidden", true); + } + private void UpdateIconVisibility() { var shouldShowIcon = ShouldShowIcon(); @@ -175,6 +183,7 @@ public sealed partial class DockItemControl : Control } UpdateIconVisibilityState(); + UpdateContentSpacingState(); } private void UpdateIconVisibilityState() @@ -182,6 +191,12 @@ public sealed partial class DockItemControl : Control VisualStateManager.GoToState(this, ShouldShowIcon() ? "IconVisible" : "IconHidden", true); } + private void UpdateContentSpacingState() + { + var showSpacing = TextVisibility != Visibility.Collapsed && HasText && ShouldShowIcon(); + VisualStateManager.GoToState(this, showSpacing ? "ContentSpacingVisible" : "ContentSpacingHidden", true); + } + private void UpdateAlignment() { HorizontalAlignment = HorizontalAlignment.Stretch;