From 32895ad1a6ad6d8923798fd7e8f9d41396ed23a6 Mon Sep 17 00:00:00 2001 From: Boris Fritscher Date: Mon, 17 Jul 2017 13:23:39 +0200 Subject: [PATCH] Refactor to transform a list of special keys into keycapborder visuals --- src/Carnac/UI/KeyShowView.xaml | 22 +---------- src/Carnac/UI/ToSpecialKeyConverter.cs | 55 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 src/Carnac/UI/ToSpecialKeyConverter.cs diff --git a/src/Carnac/UI/KeyShowView.xaml b/src/Carnac/UI/KeyShowView.xaml index 914ce248..10af6599 100644 --- a/src/Carnac/UI/KeyShowView.xaml +++ b/src/Carnac/UI/KeyShowView.xaml @@ -16,6 +16,7 @@ + @@ -149,26 +150,7 @@ - - - - - - - - - - - - - - - - - - - - + diff --git a/src/Carnac/UI/ToSpecialKeyConverter.cs b/src/Carnac/UI/ToSpecialKeyConverter.cs new file mode 100644 index 00000000..185b2858 --- /dev/null +++ b/src/Carnac/UI/ToSpecialKeyConverter.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Windows.Data; + +namespace Carnac.UI +{ + public class ToSpecialKeyConverter : IValueConverter + { + + private readonly List specialKeys = new List(){ + "Escape", + "Alt", + "Ctrl", + "Shift", + "Tab", + "Delete", + "Insert", + "Home", + "Next", + "PageUp", + "PageDown", + "End", + "Back", + "NumLock", + "PrintScreen", + "Scroll", + "Capital", + "F1", + "F2", + "F3", + "F4", + "F5", + "F6", + "F7", + "F8", + "F9", + "F10", + "F11", + "F12", + "Apps", + "BrowserHome", + }; + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return specialKeys.Contains(value.ToString()) ? "SPECIAL_KEY" : value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +}