using FluentTerminal.Models.Enums; using System; using System.ComponentModel; using Windows.UI.Xaml.Data; namespace FluentTerminal.App.Converters { public class IntToExtendedVirtualKeyConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { if (value is int intValue) { return GetEnumDescription((ExtendedVirtualKey)intValue); } return null; } public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } private static string GetEnumDescription(Enum value) { var fieldInfo = value.GetType().GetField(value.ToString()); if (fieldInfo == null) { return value.ToString(); } var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes?.Length > 0) { return attributes[0].Description; } return value.ToString(); } } }