public override void OnMouseMove(float x, float y, ICollection <FocusCandidate> focusCandidates)
        {
            base.OnMouseMove(x, y, focusCandidates);
            float xTrans = x;
            float yTrans = y;

            if (!TransformMouseCoordinates(ref xTrans, ref yTrans))
            {
                return;
            }

            _lastMouseX = _mousePositionMode == PositionCalculationMode.Relative ? xTrans / (float)ActualWidth : x;
            _lastMouseY = _mousePositionMode == PositionCalculationMode.Relative ? yTrans / (float)ActualHeight : y;
            if (!IsActive)
            {
                return;
            }
            ICommandStencil command = MouseMovedCommand;

            if (command == null)
            {
                return;
            }
            command.Execute(new object[] { _lastMouseX, _lastMouseY });
        }
        internal override void OnMouseMove(float x, float y, ICollection <FocusCandidate> focusCandidates)
        {
            //TODO: check if this could also be done in routed event OnMouseMove or OnPreviewMouseMove
            // The only difference should be that routed events get not called if mouse is not over this or a child element
            base.OnMouseMove(x, y, focusCandidates);
            float xTrans = x;
            float yTrans = y;

            if (!TransformMouseCoordinates(ref xTrans, ref yTrans))
            {
                return;
            }

            _lastMouseX = _mousePositionMode == PositionCalculationMode.Relative ? xTrans / (float)ActualWidth : x;
            _lastMouseY = _mousePositionMode == PositionCalculationMode.Relative ? yTrans / (float)ActualHeight : y;
            if (!IsActive)
            {
                return;
            }
            ICommandStencil command = MouseMovedCommand;

            if (command == null)
            {
                return;
            }
            command.Execute(new object[] { _lastMouseX, _lastMouseY });
        }
Exemple #3
0
        protected void FireSelectionChanged(object newCurrentItem)
        {
            ICommandStencil commandStencil = SelectionChanged;

            if (commandStencil != null)
            {
                commandStencil.Execute(new object[] { newCurrentItem });
            }
        }
Exemple #4
0
        public override void Dispose()
        {
            base.Dispose();
            var disposableHandler = Handler as IDisposable;

            if (disposableHandler != null)
            {
                disposableHandler.Dispose();
            }
            Handler = null;
        }
 public override void OnMouseClick(MouseButtons buttons, ref bool handled)
 {
     if (IsActive && buttons == Buttons)
     {
         ICommandStencil command = MouseClickedCommand;
         if (command == null)
         {
             return;
         }
         command.Execute(new object[] { buttons, _lastMouseX, _lastMouseY });
         handled = true;
     }
     base.OnMouseClick(buttons, ref handled);
 }
        public override void OnKeyPressed(ref Key key)
        {
            base.OnKeyPressed(ref key);
            if (!IsActive || key == Key.None)
            {
                return;
            }
            ICommandStencil command = KeyPressedCommand;

            if (command == null)
            {
                return;
            }
            command.Execute(new object[] { key });
        }
Exemple #7
0
 public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
 {
   base.DeepCopy(source, copyManager);
   var setterSource = (EventSetter) source;
   // Event property is only a alias for Property which is copied by the base class
   HandledEventsToo = setterSource.HandledEventsToo;
   var disposableHandler = Handler as IDisposable;
   if (disposableHandler != null)
   {
     disposableHandler.Dispose();
   }
   Handler = null;
   if (setterSource.Handler != null)
   {
     Handler = copyManager.GetCopy(setterSource.Handler);
   }
 }
Exemple #8
0
        public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            base.DeepCopy(source, copyManager);
            var setterSource = (EventSetter)source;

            // Event property is only a alias for Property which is copied by the base class
            HandledEventsToo = setterSource.HandledEventsToo;
            var disposableHandler = Handler as IDisposable;

            if (disposableHandler != null)
            {
                disposableHandler.Dispose();
            }
            Handler = null;
            if (setterSource.Handler != null)
            {
                Handler = copyManager.GetCopy(setterSource.Handler);
            }
        }
Exemple #9
0
 public override void Dispose()
 {
   base.Dispose();
   var disposableHandler = Handler as IDisposable;
   if (disposableHandler != null)
   {
     disposableHandler.Dispose();
   }
   Handler = null;
 }
 internal RoutedEventHandlerInfo(ICommandStencil handler, bool handledEventsToo)
     : this()
 {
     CommandStencilHandler = handler;
     HandledEventsToo      = handledEventsToo;
 }
Exemple #11
0
 /// <summary>
 /// Removes an <see cref="RoutedEvent"/> handler from this element, using a command stencil as handler.
 /// </summary>
 /// <param name="routedEvent">Routed event identifier.</param>
 /// <param name="handler">Handler of the event.</param>
 public void RemoveHandler(RoutedEvent routedEvent, ICommandStencil handler)
 {
   List<RoutedEventHandlerInfo> handlerList;
   if (_eventHandlerDictionary.TryGetValue(routedEvent, out handlerList))
   {
     for (var n = 0; n < handlerList.Count; ++n)
     {
       if (handlerList[n].CommandStencilHandler == handler)
       {
         handlerList.RemoveAt(n);
         break;
       }
     }
   }
 }
Exemple #12
0
 /// <summary>
 /// Adds an <see cref="RoutedEvent"/> handler to this element, using a command stencil as handler.
 /// </summary>
 /// <param name="routedEvent">Routed event identifier.</param>
 /// <param name="handler">Handler for the event.</param>
 /// <param name="handledEventsToo"><c>true</c> if the handler should be invoked for events that has been marked as handled; <c>false</c> for the default behavior.</param>
 public void AddHandler(RoutedEvent routedEvent, ICommandStencil handler, bool handledEventsToo)
 {
   List<RoutedEventHandlerInfo> handlerList;
   if (!_eventHandlerDictionary.TryGetValue(routedEvent, out handlerList))
   {
     handlerList = new List<RoutedEventHandlerInfo>(1);
     _eventHandlerDictionary.Add(routedEvent, handlerList);
   }
   var handlerInfo = new RoutedEventHandlerInfo(handler, handledEventsToo);
   handlerList.Add(handlerInfo);
 }
Exemple #13
0
 /// <summary>
 /// Adds an <see cref="RoutedEvent"/> handler to this element, using a command stencil as handler.
 /// </summary>
 /// <param name="routedEvent">Routed event identifier.</param>
 /// <param name="handler">Handler for the event.</param>
 public void AddHandler(RoutedEvent routedEvent, ICommandStencil handler)
 {
   AddHandler(routedEvent, handler, false);
 }
 internal RoutedEventHandlerInfo(ICommandStencil handler, bool handledEventsToo)
   : this()
 {
   CommandStencilHandler = handler;
   HandledEventsToo = handledEventsToo;
 }
Exemple #15
0
    /// <summary>
    /// Will create an event handler association for the current element, using a command markup extension as handler.
    /// </summary>
    /// <param name="obj"><see cref="UIElement"/> which defines the event to assign the event
    /// handler specified by <paramref name="commandStencil"/> to.</param>
    /// <param name="evt"><see cref="RoutedEvent"/> which is defined on the class of <paramref name="obj"/>.</param>
    /// <param name="commandStencil">Command stencil to be used as event handler.</param>
    protected void HandleEventAssignment(UIElement obj, RoutedEvent evt, ICommandStencil commandStencil)
    {
      try
      {
        // initialize command extension
        var evaluableMarkupExtension = commandStencil as IEvaluableMarkupExtension;
        if (evaluableMarkupExtension != null)
        {
          evaluableMarkupExtension.Initialize(this);
        }

        // add the event handler to the event
        obj.AddHandler(evt, commandStencil);
      }
      catch (Exception e)
      {
        throw new XamlBindingException("Error assigning event handler", e);
      }
    }