private void UpdateDisplay() { var modifiers = Modifiers == ModifierKeys.None ? "" : Modifiers.ToString(); var key = Key == Key.None ? "" : KeyboardInteropHelper.GetDisplayString(Key) ?? Key.ToString(); var mouse = MouseAction == ExtendedMouseAction.None ? "" : MouseAction.ToString(); string display; if (recordingKeyCombination) { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(modifiers)) { display = modifiers + " + " + key; } else { display = modifiers + key; //Don't add a '+' as one of them is empty. } } else { if (!string.IsNullOrEmpty(mouse) && !string.IsNullOrEmpty(modifiers)) { display = modifiers + " + " + mouse; } else { display = modifiers + mouse; //Don't add a '+' as one of them is empty. } } RecordedInput.Content = display; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is Key key) { var s = KeyboardInteropHelper.GetDisplayString(key); return(string.IsNullOrWhiteSpace(s) ? key.ToString() : s); } #if DEBUG throw new ArgumentException($"{nameof(value)} is not a `{nameof(Key)}`!", nameof(value)); #else return(""); #endif }