/// <summary> /// Constructor /// </summary> /// <param name="command">Command Associated</param> /// <param name="gesture">Mmouse Gesture associated</param> public MouseBinding(ICommand command, MouseGesture gesture) : base(command, gesture) { SynchronizePropertiesFromGesture(gesture); // Hooking the handler explicitly becuase base constructor uses _gesture // It cannot use Gesture property itself because it is a virtual gesture.PropertyChanged += new PropertyChangedEventHandler(OnMouseGesturePropertyChanged); }
/// <summary> /// Constructor /// </summary> /// <param name="command">Command Associated</param> /// <param name="gesture">Mmouse Gesture associated</param> public MouseBinding(ICommand command, MouseGesture gesture) : base(command, gesture) { SynchronizePropertiesFromGesture(gesture); // Hooking the handler explicitly becuase base constructor uses _gesture // It cannot use Gesture property itself because it is a virtual gesture.PropertyChanged += new PropertyChangedEventHandler(OnMouseGesturePropertyChanged); }
private void CloneGesture() { MouseGesture mouseGesture = Gesture as MouseGesture; if (mouseGesture != null) { mouseGesture.PropertyChanged += new PropertyChangedEventHandler(OnMouseGesturePropertyChanged); } }
private void OnMouseGesturePropertyChanged(object sender, PropertyChangedEventArgs e) { if (string.Compare(e.PropertyName, "MouseAction", StringComparison.Ordinal) == 0) { MouseGesture mouseGesture = Gesture as MouseGesture; if (mouseGesture != null) { SynchronizePropertiesFromGesture(mouseGesture); } } }
void Window3_Loaded(object sender, RoutedEventArgs e) { MouseGesture runCmdMouseGesture = new MouseGesture(); runCmdMouseGesture.MouseAction = MouseAction.LeftClick; runCmdMouseGesture.Modifiers = ModifierKeys.Control; MouseBinding runCmdMouseBinding = new MouseBinding(); runCmdMouseBinding.Gesture = runCmdMouseGesture; runCmdMouseBinding.Command = MyCommands.Run; myCanvas.InputBindings.Add(runCmdMouseBinding); }
/// <summary> /// Synchronized Properties from Gesture /// </summary> private void SynchronizePropertiesFromGesture(MouseGesture mouseGesture) { if (!_settingGesture) { _settingGesture = true; try { MouseAction = mouseGesture.MouseAction; } finally { _settingGesture = false; } } }
/// <summary> /// CanConvertToString() /// </summary> /// <param name="value"></param> /// <param name="context"></param> /// <returns></returns> /// <ExternalAPI/> public override bool CanConvertToString(object value, IValueSerializerContext context) { bool result = false; MouseGesture mouseGesture = value as MouseGesture; if (mouseGesture != null) { if (ModifierKeysConverter.IsDefinedModifierKeys(mouseGesture.Modifiers) && MouseActionConverter.IsDefinedMouseAction(mouseGesture.MouseAction)) { result = true; } } return(result); }
/// <summary> /// Constructor /// </summary> /// <param name="mouseAction">Mouse Action</param> /// <param name="modifiers">Modifiers</param> public MouseGesture(MouseAction mouseAction, ModifierKeys modifiers) // acclerator action { if (!MouseGesture.IsDefinedMouseAction(mouseAction)) { throw new InvalidEnumArgumentException("mouseAction", (int)mouseAction, typeof(MouseAction)); } if (!ModifierKeysConverter.IsDefinedModifierKeys(modifiers)) { throw new InvalidEnumArgumentException("modifiers", (int)modifiers, typeof(ModifierKeys)); } _modifiers = modifiers; _mouseAction = mouseAction; //AttachClassListeners(); }
///<summary> ///TypeConverter method override. ///</summary> ///<param name="context">ITypeDescriptorContext</param> ///<param name="destinationType">Type to convert to</param> ///<returns>true if conversion is possible</returns> public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { // We can convert to an InstanceDescriptor or to a string. if (destinationType == typeof(string)) { // When invoked by the serialization engine we can convert to string only for known type if (context != null && context.Instance != null) { MouseGesture mouseGesture = context.Instance as MouseGesture; if (mouseGesture != null) { return(ModifierKeysConverter.IsDefinedModifierKeys(mouseGesture.Modifiers) && MouseActionConverter.IsDefinedMouseAction(mouseGesture.MouseAction)); } } } return(false); }
/// <summary> /// Synchronized Gesture from properties /// </summary> private void SynchronizeGestureFromProperties(MouseAction mouseAction) { if (!_settingGesture) { _settingGesture = true; try { if (Gesture == null) { Gesture = new MouseGesture(mouseAction); } else { ((MouseGesture)Gesture).MouseAction = mouseAction; } } finally { _settingGesture = false; } } }
/// <summary> /// ConvertTo() /// </summary> /// <param name="context">Serialization Context</param> /// <param name="culture">Culture Info</param> /// <param name="value">MouseGesture value </param> /// <param name="destinationType">Type to Convert</param> /// <returns>string if parameter is a MouseGesture</returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { if (value == null) { return(String.Empty); } MouseGesture mouseGesture = value as MouseGesture; if (mouseGesture != null) { string strGesture = ""; TypeConverter modifierKeysConverter = TypeDescriptor.GetConverter(typeof(System.Windows.Input.ModifierKeys)); if (null != modifierKeysConverter) { strGesture += modifierKeysConverter.ConvertTo(context, culture, mouseGesture.Modifiers, destinationType) as string; if (strGesture != String.Empty) { strGesture += MODIFIERS_DELIMITER; } } TypeConverter mouseActionConverter = TypeDescriptor.GetConverter(typeof(System.Windows.Input.MouseAction)); if (null != mouseActionConverter) { strGesture += mouseActionConverter.ConvertTo(context, culture, mouseGesture.MouseAction, destinationType) as string; } return(strGesture); } } throw GetConvertToException(value, destinationType); }
public MouseBinding(ICommand command, MouseGesture gesture) { }
/// <summary> /// Synchronized Gesture from properties /// </summary> private void SynchronizeGestureFromProperties(MouseAction mouseAction) { if (!_settingGesture) { _settingGesture = true; try { if (Gesture == null) { Gesture = new MouseGesture(mouseAction); } else { ((MouseGesture)Gesture).MouseAction = mouseAction; } } finally { _settingGesture = false; } } }
public MouseBinding(ICommand command, MouseGesture gesture) { }
public static void ExecuteMouseGestureCommand(Control control, MouseGesture gesture) { var foo = new List<InputBinding>(control.InputBindings.Cast<InputBinding>()); var binding = foo.Where(x => x.Gesture is MouseGesture && (x.Gesture as MouseGesture).MouseAction == gesture.MouseAction && (x.Gesture as MouseGesture).Modifiers == gesture.Modifiers).FirstOrDefault(); binding.Command.Execute(null); }
/// <summary> /// Wires the trigger into the interactin hierarchy. /// </summary> /// <param name="node">The node.</param> public override void Attach(IInteractionNode node) { InputGesture gesture; if(Key != Key.None) gesture = new UnrestrictedKeyGesture(Key, Modifiers); else gesture = new MouseGesture(MouseAction, Modifiers); var uiElement = node.UIElement as UIElement; if(uiElement == null) { var ex = new CaliburnException( string.Format( "You cannot use a GestureMessageTrigger with an instance of {0}. The source element must inherit from UIElement.", node.UIElement.GetType().FullName ) ); Log.Error(ex); throw ex; } FindOrCreateLookup(uiElement, gesture) .AddTrigger(this); base.Attach(node); }
/// <summary> /// Initialize hotkeys and mouse actions /// </summary> private void InitHotkeys() { KeyGesture key_gesture = null; MouseGesture mouse_gesture = null; InputBinding bind = null; CommandBindings.Add(new CommandBinding(back_command, GoBack)); key_gesture = new KeyGesture(Key.Escape, ModifierKeys.None); mouse_gesture = new MouseGesture(MouseAction.RightClick); bind = new KeyBinding(back_command, key_gesture); InputBindings.Add(bind); bind = new MouseBinding(back_command, mouse_gesture); InputBindings.Add(bind); CommandBindings.Add(new CommandBinding(upscroll_command, RightScroll)); key_gesture = new KeyGesture(Key.Left); bind = new KeyBinding(upscroll_command, key_gesture); InputBindings.Add(bind); CommandBindings.Add(new CommandBinding(downscroll_command, LeftScroll)); key_gesture = new KeyGesture(Key.Right); bind = new KeyBinding(downscroll_command, key_gesture); InputBindings.Add(bind); CommandBindings.Add(new CommandBinding(fullscreen_command, SetFullscreen)); key_gesture = new KeyGesture(Key.F12); bind = new KeyBinding(fullscreen_command, key_gesture); InputBindings.Add(bind); }
/// <summary> /// Synchronized Properties from Gesture /// </summary> private void SynchronizePropertiesFromGesture(MouseGesture mouseGesture) { if (!_settingGesture) { _settingGesture = true; try { MouseAction = mouseGesture.MouseAction; } finally { _settingGesture = false; } } }