Exemple #1
0
        /// <summary>
        /// Attach events to a visual
        /// </summary>
        /// <param name="obj">Object with which event is attached</param>
        /// <param name="senderElement">sender will be passed to the event-handler</param>
        /// <param name="visual">visual object with which event will be attached</param>
        internal static void AttachEvents2Visual(VisifireElement chartElement, VisifireElement senderElement, FrameworkElement visual)
        {
            if (visual == null)
            {
                return;
            }
            object eventHandler = null;

            // Attach event for MouseEnter
            eventHandler = chartElement.GetMouseEnterEventHandler();

            if (eventHandler != null)
            {
                visual.MouseEnter += delegate(object sender, MouseEventArgs e)
                {
                    chartElement.FireMouseEnterEvent(senderElement, e);
                }
            }
            ;

            // Attach event for MouseLeave
            eventHandler = chartElement.GetMouseLeaveEventHandler();

            if (eventHandler != null)
            {
                visual.MouseLeave += delegate(object sender, MouseEventArgs e)
                {
                    chartElement.FireMouseLeaveEvent(senderElement, e);
                }
            }
            ;

            // Attach event for MouseLeftButtonDown
            eventHandler = chartElement.GetMouseLeftButtonDownEventHandler();

            if (eventHandler != null)
            {
                visual.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseLeftButtonDownEvent(senderElement, e);
                }
            }
            ;

            // Attach event for MouseLeftButtonUp
            eventHandler = chartElement.GetMouseLeftButtonUpEventHandler();

            if (eventHandler != null)
            {
                visual.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseLeftButtonUpEvent(senderElement, e);
                }
            }
            ;

            // Attach event for MouseMove
            eventHandler = chartElement.GetMouseMoveEventHandler();

            if (eventHandler != null)
            {
                visual.MouseMove += delegate(object sender, MouseEventArgs e)
                {
                    chartElement.FireMouseMoveEvent(senderElement, e);
                }
            }
            ;

            #region RightMouseButtonEvents4WPF
#if WPF
            // Attach event for MouseLeftButtonDown
            eventHandler = chartElement.GetMouseRightButtonDownEventHandler();

            if (eventHandler != null)
            {
                visual.MouseRightButtonDown += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseRightButtonDownEvent(senderElement, e);
                }
            }
            ;

            // Attach event for MouseRightButtonUp
            eventHandler = chartElement.GetMouseRightButtonUpEventHandler();

            if (eventHandler != null)
            {
                visual.MouseRightButtonUp += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseRightButtonUpEvent(senderElement, e);
                }
            }
            ;
#endif
            #endregion
        }
        /// <summary>
        /// Attach events to a visual
        /// </summary>
        /// <param name="obj">Object with which event is attached</param>
        /// <param name="senderElement">sender will be passed to the event-handler</param>
        /// <param name="visual">visual object with which event will be attached</param>
        internal static void AttachEvents2Visual(VisifireElement chartElement, VisifireElement senderElement, FrameworkElement visual)
        {
            if (visual == null)
                return;
            object eventHandler = null;

            // Attach event for MouseEnter
            eventHandler = chartElement.GetMouseEnterEventHandler();

            if (eventHandler != null)
                visual.MouseEnter += delegate(object sender, MouseEventArgs e)
                {   
                    chartElement.FireMouseEnterEvent(senderElement, e);
                };

            // Attach event for MouseLeave
            eventHandler = chartElement.GetMouseLeaveEventHandler();

            if (eventHandler != null)
                visual.MouseLeave += delegate(object sender, MouseEventArgs e)
                {   
                    chartElement.FireMouseLeaveEvent(senderElement, e);
                };

            // Attach event for MouseLeftButtonDown
            eventHandler = chartElement.GetMouseLeftButtonDownEventHandler();

            if (eventHandler != null)
                visual.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseLeftButtonDownEvent(senderElement, e);
                };

            // Attach event for MouseLeftButtonUp
            eventHandler = chartElement.GetMouseLeftButtonUpEventHandler();
            
            if (eventHandler != null)
                visual.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseLeftButtonUpEvent(senderElement, e);
                };

            // Attach event for MouseMove
            eventHandler = chartElement.GetMouseMoveEventHandler();

            if (eventHandler != null)
                visual.MouseMove += delegate(object sender, MouseEventArgs e)
                {
                    chartElement.FireMouseMoveEvent(senderElement, e);
                };

            #region RightMouseButtonEvents4WPF
#if WPF     
            // Attach event for MouseLeftButtonDown
            eventHandler = chartElement.GetMouseRightButtonDownEventHandler();

            if (eventHandler != null)
                visual.MouseRightButtonDown += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseRightButtonDownEvent(senderElement, e);
                };

            // Attach event for MouseRightButtonUp
            eventHandler = chartElement.GetMouseRightButtonUpEventHandler();

            if (eventHandler != null)
                visual.MouseRightButtonUp += delegate(object sender, MouseButtonEventArgs e)
                {
                    chartElement.FireMouseRightButtonUpEvent(senderElement, e);
                };
#endif
            #endregion
        }