From f537c43139ad5fcffe0499fc8139becdc025cd7f Mon Sep 17 00:00:00 2001 From: Noraa Junker Date: Mon, 27 Oct 2025 23:36:17 +0100 Subject: [PATCH] Added right key visuals and fixed some UI bugs --- .../ShortcutDescriptionToKeysConverter.cs | 3 + .../Helpers/StringResourceExtension.cs | 30 ++++++++ .../Controls/KeyCharPresenter.xaml | 23 +++++++ .../Controls/KeyCharPresenter.xaml.cs | 2 + .../Controls/KeyVisual.xaml.cs | 69 ++++++++++--------- .../ShortcutGuideXAML/MainWindow.xaml | 26 ++++--- .../ShortcutGuideXAML/MainWindow.xaml.cs | 28 ++++++-- .../ShortcutGuideXAML/Pages/OverviewPage.xaml | 8 ++- .../Strings/en-us/Resources.resw | 10 +++ 9 files changed, 152 insertions(+), 47 deletions(-) create mode 100644 src/modules/ShortcutGuide/ShortcutGuide.Ui/Helpers/StringResourceExtension.cs diff --git a/src/modules/ShortcutGuide/ShortcutGuide.Ui/Converters/ShortcutDescriptionToKeysConverter.cs b/src/modules/ShortcutGuide/ShortcutGuide.Ui/Converters/ShortcutDescriptionToKeysConverter.cs index a90ee31c40..38824b30bc 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide.Ui/Converters/ShortcutDescriptionToKeysConverter.cs +++ b/src/modules/ShortcutGuide/ShortcutGuide.Ui/Converters/ShortcutDescriptionToKeysConverter.cs @@ -84,6 +84,9 @@ namespace ShortcutGuide.Converters case "Back": shortcutList.Add(8); // The Back key or button. break; + case "": + shortcutList.Add("Num"); + break; default: shortcutList.Add(key); // Add other keys as strings. break; diff --git a/src/modules/ShortcutGuide/ShortcutGuide.Ui/Helpers/StringResourceExtension.cs b/src/modules/ShortcutGuide/ShortcutGuide.Ui/Helpers/StringResourceExtension.cs new file mode 100644 index 0000000000..c25c18b527 --- /dev/null +++ b/src/modules/ShortcutGuide/ShortcutGuide.Ui/Helpers/StringResourceExtension.cs @@ -0,0 +1,30 @@ +// 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.Markup; + +namespace ShortcutGuide.Helpers +{ + [MarkupExtensionReturnType(ReturnType = typeof(string))] + public partial class StringResourceExtension : MarkupExtension + { + public enum SpecialTreatment + { + None, + FirstCharOnly, + EverythingExceptFirstChar, + } + + public string Key { get; set; } = string.Empty; + + public SpecialTreatment Treatment { get; set; } = SpecialTreatment.None; + + protected override object ProvideValue() => Treatment switch + { + SpecialTreatment.FirstCharOnly => ResourceLoaderInstance.ResourceLoader.GetString(Key)[0].ToString(), + SpecialTreatment.EverythingExceptFirstChar => ResourceLoaderInstance.ResourceLoader.GetString(Key)[1..], + _ => ResourceLoaderInstance.ResourceLoader.GetString(Key), + }; + } +} diff --git a/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/Controls/KeyCharPresenter.xaml b/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/Controls/KeyCharPresenter.xaml index 228276544d..0d962c3be8 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/Controls/KeyCharPresenter.xaml +++ b/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuideXAML/Controls/KeyCharPresenter.xaml @@ -3,10 +3,12 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:ShortcutGuide.Controls" + xmlns:helpers="using:ShortcutGuide.Helpers" xmlns:ui="using:CommunityToolkit.WinUI"> +