using System; using System.Collections.ObjectModel; using System.Globalization; using System.Windows.Data; using System.Windows.Input; using ICSharpCode.Core.Presentation; namespace ICSharpCode.ShortcutsManagement.Converters { /// /// Converts input gestures collection into string /// public class GesturesListConverter : IValueConverter { /// /// Convert collection of gestures to a string /// /// Collection of gestures /// Convertion target type (only string is supported) /// Not used /// Not used /// String representing collection of gestures public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string converterValue = ""; if (value is InputGestureCollection && (targetType == typeof(string) || targetType.IsSubclassOf(typeof(string)))) { converterValue = new InputGestureCollectionConverter().ConvertToInvariantString(value); } if (value is ObservableCollection && (targetType == typeof(string) || targetType.IsSubclassOf(typeof(string)))) { var inputGestureCollection = new InputGestureCollection(); foreach (var gesture in (ObservableCollection)value) { inputGestureCollection.Add(gesture); } converterValue = new InputGestureCollectionConverter().ConvertToInvariantString(inputGestureCollection); } return converterValue.Replace("+", " + ").Replace(",", ", ").Replace(";", "; "); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } }