From bb706fb5f1112e8db21cd5b3bd2773c40bdb51d0 Mon Sep 17 00:00:00 2001 From: Sam Rueby Date: Mon, 22 Sep 2025 10:20:39 -0400 Subject: [PATCH] Only include a margin if there is text to separate from the icon. (#41851) ## Summary of the Pull Request Implemented conditional margin for tags with icons that do not included text. ## PR Checklist - [ X ] Closes: #41828 - [ ] **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 Created a new IValueConverter for icon margin to conditionally remove margin when Text is empty. ## Validation Steps Performed Below is a screenshot of the previous behavior. image Below is a screenshot of the new behavior. image --- .../Controls/IconMarginConverter.cs | 20 +++++++++++++++++++ .../Microsoft.CmdPal.UI/Controls/Tag.xaml | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconMarginConverter.cs diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconMarginConverter.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconMarginConverter.cs new file mode 100644 index 0000000000..0fb1e736f5 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IconMarginConverter.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Data; + +namespace Microsoft.CmdPal.UI.Controls; + +public sealed class IconMarginConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, string language) + { + // Only include a margin if there is text to separate from the icon. + var text = value as string; + return string.IsNullOrEmpty(text) ? new Thickness(0) : new Thickness(0, 0, 4, 0); + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException(); +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/Tag.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/Tag.xaml index aec0bb380e..7cf917b21c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/Tag.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/Tag.xaml @@ -27,6 +27,8 @@ 4,2,4,2 1 + +