/// <summary> /// Updates the value of the <see cref="Gesture"/> property based on the current property values of this binding. /// </summary> private void UpdateGestureFromBinding() { if (updating) { return; } updating = true; Gesture = new MouseGesture(MouseAction, Modifiers); updating = false; }
/// <summary> /// Converts the string representation of a gesture into an instance of the <see cref="MouseGesture"/> structure. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="str">A string containing a gesture to convert.</param> /// <param name="provider">A format provider that provides culture-specific formatting information.</param> /// <param name="gesture">A variable to populate with the converted value.</param> /// <returns><see langword="true"/> if <paramref name="str"/> was converted successfully; otherwise, <see langword="false"/>.</returns> public static Boolean TryParse(String str, IFormatProvider provider, out MouseGesture gesture) { Contract.Require(str, nameof(str)); gesture = null; if (String.IsNullOrWhiteSpace(str)) { return(false); } var mouseAction = MouseAction.None; var modifiers = ModifierKeys.None; var parts = str.Split('+').Select(x => x.Trim()).ToArray(); for (int i = 0; i < parts.Length; i++) { var isModifier = (i + 1 < parts.Length); if (isModifier) { var modFromStr = GetModifierKeyFromString(parts[i]); if (modFromStr == null || (modifiers & modFromStr.GetValueOrDefault()) != 0) { return(false); } modifiers |= modFromStr.GetValueOrDefault(); } else { if (!Enum.TryParse(parts[i], true, out mouseAction)) { return(false); } } } gesture = new MouseGesture(mouseAction, modifiers); return(true); }
/// <summary> /// Converts the string representation of a gesture into an instance of the <see cref="MouseGesture"/> structure. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="str">A string containing a gesture to convert.</param> /// <param name="gesture">A variable to populate with the converted value.</param> /// <returns><see langword="true"/> if <paramref name="str"/> was converted successfully; otherwise, <see langword="false"/>.</returns> public static Boolean TryParse(String str, out MouseGesture gesture) { return(TryParse(str, null, out gesture)); }
/// <summary> /// Initializes a new instance of the <see cref="MouseBinding"/> class. /// </summary> /// <param name="command">The command associated with the specified gesture.</param> /// <param name="gesture">The gesture associated with the specified command.</param> public MouseBinding(ICommand command, MouseGesture gesture) : base(command, gesture) { }