Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
KeyGestureExtension.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Windows.Input;
5 using System.Windows.Markup;
6 
7 namespace SiliconStudio.Presentation.MarkupExtensions
8 {
9  /// <summary>
10  /// This markup extension allows to create a <see cref="KeyGesture"/> instance from a string representing the gesture.
11  /// </summary>
13  {
14  /// <summary>
15  /// Gets or sets the key gesture.
16  /// </summary>
17  public KeyGesture Gesture { get; set; }
18 
19  /// <summary>
20  /// Initializes a new instance of the <see cref="KeyGestureExtension"/> class with a string representing the gesture.
21  /// </summary>
22  /// <param name="gesture">A string representing the gesture.</param>
23  public KeyGestureExtension(string gesture)
24  {
25  var modifiers = ModifierKeys.None;
26  var tokens = gesture.Split('+');
27  for (int i = 0; i < tokens.Length - 1; ++i)
28  {
29  var token = tokens[i].Replace("Ctrl", "Control");
30  var modifier = (ModifierKeys)Enum.Parse(typeof(ModifierKeys), token, true);
31  modifiers |= modifier;
32  }
33  var key = (Key)Enum.Parse(typeof(Key), tokens[tokens.Length - 1], true);
34  Gesture = new KeyGesture(key, modifiers);
35  }
36 
37  /// <inheritdoc/>
38  public override object ProvideValue(IServiceProvider serviceProvider)
39  {
40  return Gesture;
41  }
42  }
43 }
This markup extension allows to create a KeyGesture instance from a string representing the gesture...
KeyGestureExtension(string gesture)
Initializes a new instance of the KeyGestureExtension class with a string representing the gesture...
override object ProvideValue(IServiceProvider serviceProvider)