KeyChordToStringConverter.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.CommandPalette.Extensions; 6 using Microsoft.UI.Xaml.Data; 7 using Windows.System; 8 using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance; 9 10 namespace Microsoft.CmdPal.UI; 11 12 public partial class KeyChordToStringConverter : IValueConverter 13 { 14 public object Convert(object value, Type targetType, object parameter, string language) 15 { 16 if (value is KeyChord shortcut && (VirtualKey)shortcut.Vkey != VirtualKey.None) 17 { 18 var result = string.Empty; 19 20 if (shortcut.Modifiers.HasFlag(VirtualKeyModifiers.Control)) 21 { 22 result += "Ctrl+"; 23 } 24 25 if (shortcut.Modifiers.HasFlag(VirtualKeyModifiers.Shift)) 26 { 27 result += "Shift+"; 28 } 29 30 if (shortcut.Modifiers.HasFlag(VirtualKeyModifiers.Menu)) 31 { 32 result += "Alt+"; 33 } 34 35 result += (VirtualKey)shortcut.Vkey; 36 37 return result; 38 } 39 40 return string.Empty; 41 } 42 43 public object ConvertBack(object value, Type targetType, object parameter, string language) 44 { 45 throw new NotImplementedException(); 46 } 47 }