Esempio n. 1
0
        private static void MouseUpCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement element = (FrameworkElement)d;

            element.AddHandler(Mouse.MouseEnterEvent, new MouseEventHandler(OnMouseEvent));
            element.AddHandler(Mouse.MouseLeaveEvent, new MouseEventHandler(OnMouseEvent));
        }
Esempio n. 2
0
        public void AttachCommandHandlers(FrameworkElement sender)
        {
            sender.AddHandler(CommandManager.PreviewCanExecuteEvent, new CanExecuteRoutedEventHandler(PreviewCanExecuteHandler), true);
            sender.AddHandler(CommandManager.CanExecuteEvent, new CanExecuteRoutedEventHandler(CanExecuteHandler), true);

            sender.AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(PreviewExecutedHandler), true);
            sender.AddHandler(CommandManager.ExecutedEvent, new ExecutedRoutedEventHandler(ExecutedHandler), true);
        }
 protected override void OnApplyTemplate()
 {
     sliderContainer = GetTemplateChild("SliderContainer") as FrameworkElement;
     if (sliderContainer != null)
     {
         sliderContainer.PointerPressed += SliderContainer_PointerPressed;
         sliderContainer.AddHandler(PointerPressedEvent, new PointerEventHandler(SliderContainer_PointerPressed), true);
         sliderContainer.AddHandler(PointerReleasedEvent, new PointerEventHandler(SliderContainer_PointerReleased), true);
         sliderContainer.AddHandler(PointerCanceledEvent, new PointerEventHandler(SliderContainer_PointerReleased), true);
         sliderContainer.AddHandler(PointerCaptureLostEvent, new PointerEventHandler(SliderContainer_PointerReleased), true);
         sliderContainer.ManipulationMode       = Orientation == Orientation.Vertical ? ManipulationModes.TranslateY : ManipulationModes.TranslateX;
         sliderContainer.ManipulationStarted   += SliderContainer_ManipulationStarted;
         sliderContainer.ManipulationDelta     += SliderContainer_ManipulationDelta;
         sliderContainer.ManipulationCompleted += SliderContainer_ManipulationCompleted;
         sliderContainer.Unloaded         += SliderContainer_Unloaded;
         sliderContainerPointerOverManager = new PointerOverManager(sliderContainer, true);
         sliderContainerPointerOverManager.IsPointerOverChanged += SliderContainerPointerOverManager_IsPointerOverChanged;
     }
     horizontalTemplate = GetTemplateChild("HorizontalTemplate") as Grid;
     if (horizontalTemplate != null)
     {
         horizontalTemplate.SizeChanged += HorizontalTemplate_SizeChanged;
     }
     horizontalThumb = GetTemplateChild("HorizontalThumb") as FrameworkElement;
     if (horizontalThumb != null)
     {
         horizontalThumb.RenderTransform = horizontalThumbTransform;
         horizontalThumb.SizeChanged    += HorizontalThumb_SizeChanged;
     }
     horizontalDecreaseRect = GetTemplateChild("HorizontalDecreaseRect") as FrameworkElement;
     if (horizontalDecreaseRect != null)
     {
         horizontalDecreaseRect.RenderTransform       = horizontalDecreaseRectTransform;
         horizontalDecreaseRect.RenderTransformOrigin = new Point(0.0, 0.5);
     }
     verticalTemplate = GetTemplateChild("VerticalTemplate") as Grid;
     if (verticalTemplate != null)
     {
         verticalTemplate.SizeChanged += VerticalTemplate_SizeChanged;
     }
     verticalThumb = GetTemplateChild("VerticalThumb") as FrameworkElement;
     if (verticalThumb != null)
     {
         verticalThumb.RenderTransform = verticalThumbTransform;
         verticalThumb.SizeChanged    += VerticalThumb_SizeChanged;
     }
     verticalDecreaseRect = GetTemplateChild("VerticalDecreaseRect") as FrameworkElement;
     if (verticalDecreaseRect != null)
     {
         verticalDecreaseRect.RenderTransform       = horizontalDecreaseRectTransform;
         verticalDecreaseRect.RenderTransformOrigin = new Point(0.5, 1.0);
     }
     base.OnApplyTemplate();
     UpdateControls();
 }
Esempio n. 4
0
        /// <summary>
        /// 开启倾斜效果。
        /// </summary>
        /// <param name="element">要开启倾斜效果的元素。</param>
        private void Enable(FrameworkElement element)
        {
            _target = element;

            _tiltDownStoryboard = new Lazy <Storyboard>(() => CreateTiltStoryboard(element, true));
            _tiltUpStoryboard   = new Lazy <Storyboard>(() => CreateTiltStoryboard(element, false));

            element.AddHandler(UIElement.MouseLeftButtonDownEvent, _downHandler, true);
            element.AddHandler(UIElement.MouseLeftButtonUpEvent, _upHandler, true);
            element.AddHandler(UIElement.MouseLeaveEvent, _leaveHandler, true);
        }
Esempio n. 5
0
        private static void onCheckingKeyChanged(DependencyObject target, Key value)
        {
            FrameworkElement element = target as FrameworkElement;

            if (element == null)
            {
                return;
            }
            element.PreviewMouseMove += element_PreviewMouseMove;
            element.Focusable         = true;
            element.AddHandler(FrameworkElement.PreviewKeyDownEvent, new KeyEventHandler(checkKey), true);
            element.AddHandler(FrameworkElement.PreviewKeyUpEvent, new KeyEventHandler(checkKey), true);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MouseClickWrapper"/> class with specified FrameworkElement as mouse events source and specified MouseButton
        /// to notify about its clicks.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="mouseButton">The mouse button.</param>
        public MouseClickWrapper(FrameworkElement element, MouseButton mouseButton)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            this.element     = element;
            this.mouseButton = mouseButton;

            element.AddHandler(FrameworkElement.MouseDownEvent, new MouseButtonEventHandler(OnMouseDown));
            element.AddHandler(FrameworkElement.MouseUpEvent, new MouseButtonEventHandler(OnMouseUp));
        }
Esempio n. 7
0
        /// <summary>
        /// Initializing constructor
        /// </summary>
        /// <param name="dragSource">Element to be the source of a drag operation</param>
        public DragHelper(FrameworkElement dragSource)
        {
            _dragSource = dragSource;

            _dragSource.AddHandler(FrameworkElement.MouseLeftButtonDownEvent,
                                   new MouseButtonEventHandler(OnMouseLeftButtonDown), true);
            _dragSource.AddHandler(FrameworkElement.MouseLeftButtonUpEvent,
                                   new MouseButtonEventHandler(OnMouseLeftButtonUp), true);
            _dragSource.AddHandler(FrameworkElement.MouseMoveEvent,
                                   new MouseEventHandler(OnMouseMove), true);

            _dragSource.GiveFeedback += OnGiveFeedback;
        }
Esempio n. 8
0
 private void InitializeDropDown()
 {
     _dropDownContent    = ResultsBoxTemplate.LoadContent() as FrameworkElement;
     _dropDown           = new PopupAdorner(_searchTextBox, _dropDownContent);
     _resultsItemControl = _dropDownContent.FindName("PART_ResultsItemControl") as ItemsControl;
     _dropDownContent.SetBinding(FrameworkElement.DataContextProperty, new Binding("DataContext")
     {
         Source = this
     });
     _dropDownContent.AddHandler(ResultItem.ResultItemSelectedEvent, new RoutedEventHandler(OnResultItemSelected));
     _dropDownContent.AddHandler(ResultItem.ResultItemClickedEvent, new RoutedEventHandler(OnResultItemClicked));
     _dropDownContent.MouseDown += PopupContent_MouseDown;
 }
Esempio n. 9
0
        public static void SetEventDetection(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement objectToDetectEventOn =
                GetObjectToDetectEventOn(sender);

            if (objectToDetectEventOn == null)
            {
                return;
            }

            RoutedEvent routedEvent = GetTheEventToDetect(sender);

            if (routedEvent == null)
            {
                return;
            }

            FrameworkElement currentEl = (FrameworkElement)sender;

            void Handler(object obj, RoutedEventArgs routedEventArgs)
            {
                routedEventArgs.RoutedEvent = DetectedEvent;
                currentEl.RaiseEvent(routedEventArgs);
            }

            objectToDetectEventOn.AddHandler(routedEvent, (RoutedEventHandler)Handler);
        }
Esempio n. 10
0
        private static void OnRoutedEventCommand(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement sender = d as FrameworkElement;

            if (sender == null)
            {
                return;
            }
            var oldValue = e.OldValue as RoutedEvent;

            if (oldValue != null)
            {
                sender.RemoveHandler(oldValue, new MouseButtonEventHandler(OnElementMouseDown));
            }
            var routedEvent = e.NewValue as RoutedEvent;

            if (routedEvent != null)
            {
                if (sender.IsLoaded)
                {
                    sender.AddHandler(routedEvent, new MouseButtonEventHandler(OnElementMouseDown));
                }
                sender.Unloaded += OnElementUnloaded;

                sender.Loaded += OnElementLoaded;
            }
        }
        /// <summary>
        ///     The set root visual.
        /// </summary>
        private static void SetRootVisual()
        {
            lock (Locker)
            {
                if ((RootVisual != null) || (Application.Current == null))
                {
                    return;
                }

                RootVisual = BrowserInteropHelper.IsBrowserHosted ? null :
                             (Application.Current.MainWindow.Content as FrameworkElement) != null ?
                             Application.Current.MainWindow.Content as FrameworkElement : Application.Current.MainWindow;

                if (RootVisual == null)
                {
                    return;
                }

                RootVisual.MouseMove += OnRootVisualMouseMove;
                RootVisual.AddHandler(
                    UIElement.MouseLeftButtonDownEvent,
                    new MouseButtonEventHandler(OnRootVisualMouseLeftButtonDown),
                    true);
            }
        }
Esempio n. 12
0
        /// <summary>
        ///     The set root visual.
        /// </summary>
        /// <param name="frameworkElement"></param>
        private static void SetRootVisual(FrameworkElement frameworkElement)
        {
            lock (Locker)
            {
                if (Application.Current == null)
                {
                    return;
                }

                if (RootVisual != null)
                {
                    RootVisual.MouseMove -= OnRootVisualMouseMove;
                }

                RootVisual = frameworkElement.GetVisualRoot() as FrameworkElement
                             ?? Application.Current.MainWindow.Content as FrameworkElement
                             ?? Application.Current.MainWindow;

                if (RootVisual == null)
                {
                    return;
                }

                RootVisual.MouseMove += OnRootVisualMouseMove;
                RootVisual.AddHandler(
                    UIElement.MouseLeftButtonDownEvent,
                    new MouseButtonEventHandler(OnRootVisualMouseLeftButtonDown),
                    true);
            }
        }
 private void AddEventsToFrameworkElement(FrameworkElement element)
 {
     element.LostFocus += this.FrameworkElementLostFocusHandler;
     element.GotFocus  += this.FrameworkElementGotFocusHandler;
     element.AddHandler(
         UIElement.GettingFocusEvent,
         FrameworkElementGettingFocusHandler,
         true                 /*handledEventsToo*/
         );
     element.AddHandler(
         UIElement.LosingFocusEvent,
         FrameworkElementLosingFocusHandler,
         true                 /*handledEventsToo*/
         );
     element.NoFocusCandidateFound += this.FrameworkElementNoFocusCandidateFoundHandler;
 }
Esempio n. 14
0
 public DragListener(FrameworkElement target)
 {
     this.target = target;
     target.AddHandler(Mouse.MouseDownEvent, new MouseButtonEventHandler(MouseButtonDown), true);
     target.PreviewMouseMove         += MouseMove;
     target.PreviewMouseLeftButtonUp += MouseLeftButtonUp;
 }
Esempio n. 15
0
        private void AddChildToPlotter(CapturingPlotter plotter)
        {
            if (plotter.Children.Count == 0 && childCreateHandler != null)
            {
                int plotterIndex = Array.IndexOf <CapturingPlotter>(plotters, plotter);


                var child = childCreateHandler();
                if (plotterIndex == 0)
                {
                    FrameworkElement element = (FrameworkElement)child;
                    element.AddHandler(Viewport2D.ContentBoundsChangedEvent, new RoutedEventHandler(OnChildContentBoundsChanged));
                    element.AddHandler(BackgroundRenderer.UpdateRequested, new RoutedEventHandler(OnChildUpdateRequested));
                }
                plotter.Children.Add(child);
            }
        }
Esempio n. 16
0
        private static void OnElementLoaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement item = sender as FrameworkElement;

            RoutedEvent routedEvent = GetRoutedEventCommand(item);

            item.AddHandler(routedEvent, new MouseButtonEventHandler(OnElementMouseDown));
        }
Esempio n. 17
0
 public void AttachEvents(FrameworkElement elt, bool dragInBackground)
 {
     elt.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, (MouseButtonEventHandler)InitiateDrag, dragInBackground);
     elt.AllowDrop  = true;
     elt.DragOver  += DragOver;
     elt.DragLeave += DragLeave;
     elt.Drop      += Drop;
 }
    public static void AddClickHandler(DependencyObject o, RoutedEventHandler handler)
    {
        FrameworkElement element = (FrameworkElement)o;

        element.AddHandler(ClickEvent, handler);
        element.MouseLeftButtonUp          += new System.Windows.Input.MouseButtonEventHandler(SimulatedClick_MouseLeftButtonUp);
        element.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(SimulatedClick_MouseLeftButtonDown);
    }
Esempio n. 19
0
 public virtual void SetOrientationProvider(FrameworkElement control)
 {
     if (control != null)
     {
         CurrentControl = control;
         control.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(HandleOwnerMouseRightButtonDown), true);
     }
 }
Esempio n. 20
0
 public void Attach(FrameworkElement element)
 {
     if (IsInDesigner)
     {
         return;
     }
     this.AnimationTarget = element;
     if (!element.IsLoaded)
     {
         element.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(this.OnLoaded));
     }
     else
     {
         this.OnLoaded(element, EventArgs.Empty);
     }
     element.AddHandler(FrameworkElement.UnloadedEvent, new RoutedEventHandler(this.OnUnloaded));
 }
Esempio n. 21
0
        /// <inheritdoc/>
        protected override void OnValueAssociated(FrameworkElement targetObject, BehaviorActionCollection <DependencyObject> newValue)
        {
            base.OnValueAssociated(targetObject, newValue);

            Require.NotNull(targetObject, nameof(targetObject));

            targetObject.AddHandler(_routedEvent, (RoutedEventHandler)OnEvent);
        }
Esempio n. 22
0
        /// <summary>
        /// Handles a change to the undo manager for a given dependency object.
        /// </summary>
        /// <param name="dependencyObject">The target object for this attached property.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The event parameters.</param>
        private static void OnUndoScopeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // This will remove the high level handlers for the root node in the UndoManager scope.
            if (dependencyPropertyChangedEventArgs.OldValue is UndoManager)
            {
                // This is the manager that was previously associated with the root of the Undo Scope.
                UndoManager undoManager = dependencyPropertyChangedEventArgs.OldValue as UndoManager;

                // This will remove a handler for the mouse focus events.
                undoManager.focusUndo.Unregister(dependencyObject);

                // This will remove the UndoManager from all the child controls.
                dependencyObject.ClearValue(UndoManager.UndoManagerProperty);

                // This will remove the handlers for the undo/redo operations for the given undo manager.
                if (dependencyObject is FrameworkElement)
                {
                    FrameworkElement frameworkElement = dependencyObject as FrameworkElement;
                    frameworkElement.RemoveHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(undoManager.OnCommand));
                }

                //// This will remove the handlers for the undo/redo operations for the given undo manager.
                if (dependencyObject is FrameworkContentElement)
                {
                    FrameworkContentElement frameworkContentElement = dependencyObject as FrameworkContentElement;
                    frameworkContentElement.RemoveHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(undoManager.OnCommand));
                }
            }

            // This will add the high level handlers for the root node in the UndoManager scope.
            if (dependencyPropertyChangedEventArgs.NewValue is UndoManager)
            {
                // This is the manager that will be used for this Undo Scope to manage the Undo and Redo operations.
                UndoManager undoManager = dependencyPropertyChangedEventArgs.NewValue as UndoManager;

                // This will add a handler for the mouse focus events.
                undoManager.focusUndo.Register(dependencyObject);

                // This adds the Undo Manager to all the child windows in the scope of this user interface element which forms
                // the root of the scope.
                dependencyObject.SetValue(UndoManager.UndoManagerProperty, undoManager);

                // This will add the handlers for the undo/redo operations for the given undo manager.
                if (dependencyObject is FrameworkElement)
                {
                    FrameworkElement frameworkElement = dependencyObject as FrameworkElement;
                    frameworkElement.AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(undoManager.OnCommand), true);
                }

                //// This will add the handlers for the undo/redo operations for the given undo manager.
                if (dependencyObject is FrameworkContentElement)
                {
                    FrameworkContentElement frameworkContentElement = dependencyObject as FrameworkContentElement;
                    frameworkContentElement.AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(undoManager.OnCommand), true);
                }
            }
        }
Esempio n. 23
0
        protected override void OnAttached(FrameworkElement associatedObject)
        {
            var button = associatedObject as Button;

            if (button != null)
            {
                associatedObject.AddHandler(Button.ClickEvent, new RoutedEventHandler(this.OnClick));
            }
        }
    public static void AddOnInvokeHandler(DependencyObject d, RoutedEventHandler handler)
    {
        FrameworkElement uie = d as FrameworkElement;

        if (uie != null)
        {
            uie.AddHandler(OnInvokeEvent, handler);
        }
    }
Esempio n. 25
0
        private static void OnEventChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement el          = (FrameworkElement)d;
            RoutedEvent      routedEvent = GetEventToConsume(el);

            if (routedEvent != null)
            {
                el.RemoveHandler(routedEvent, (RoutedEventHandler)OnEvent);
                el.AddHandler(routedEvent, (RoutedEventHandler)OnEvent);
            }
        }
Esempio n. 26
0
 private void HookEvents(FrameworkElement elt)
 {
     elt.AddHandler(PointerEnteredEvent, new PointerEventHandler((snd, e) => Log("[ENTERED]", e)), handledEventsToo: true);
     elt.AddHandler(PointerPressedEvent, new PointerEventHandler((snd, e) => Log("[PRESSED]", e)), handledEventsToo: true);
     elt.AddHandler(PointerMovedEvent, new PointerEventHandler((snd, e) => Log("[MOVED]", e)), handledEventsToo: true);
     elt.AddHandler(PointerReleasedEvent, new PointerEventHandler((snd, e) => Log("[RELEASED]", e)), handledEventsToo: true);
     elt.AddHandler(PointerExitedEvent, new PointerEventHandler((snd, e) => Log("[EXITED]", e)), handledEventsToo: true);
     elt.AddHandler(PointerCanceledEvent, new PointerEventHandler((snd, e) => Log("[CANCELED]", e)), handledEventsToo: true);
     elt.AddHandler(PointerCaptureLostEvent, new PointerEventHandler((snd, e) => Log("[CAPTURE_LOST]", e)), handledEventsToo: true);
 }
Esempio n. 27
0
        /// <summary>
        /// Wires up an event to the target
        /// </summary>
        /// <param name="target"></param>
        internal void Subscribe(object target)
        {
            string eventName = Event;

            if (target != null)
            {
                BindingOperations.SetBinding(this, FrameworkElement.DataContextProperty,
                                             new Binding("DataContext")
                {
                    Source = target
                });

                EventInfo ei = target.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance);
                if (ei != null)
                {
                    ei.RemoveEventHandler(target, GetEventMethod(ei));
                    ei.AddEventHandler(target, GetEventMethod(ei));
                    return;
                }

                // If the name has a colon namespace declaration, then drop that off.
                int dotPos = eventName.IndexOf(':');
                if (dotPos > 0)
                {
                    eventName = eventName.Substring(dotPos + 1);
                }

                // Look for an attached event on a Dependency Property
                dotPos = eventName.IndexOf('.');
                if (dotPos > 0 && eventName.Length > dotPos)
                {
                    // Scan the event manager for the specified event.
                    var attachedEvent = EventManager.GetRoutedEvents().Where(evt => evt.ToString() == eventName).SingleOrDefault();
                    if (attachedEvent != null)
                    {
                        FrameworkElement fe = target as FrameworkElement;
                        if (fe == null)
                        {
                            Debug.WriteLine(string.Format("Failed to cast Target {0} to FrameworkElement to subscribe to attached event {1}", target, eventName));
                        }
                        else
                        {
                            fe.RemoveHandler(attachedEvent, GetRoutedEventMethod());
                            fe.AddHandler(attachedEvent, GetRoutedEventMethod());
                        }
                    }
                    return;
                }
            }

            Debug.WriteLine(string.Format("Unable to locate event {0} on {1}", eventName, target));
        }
Esempio n. 28
0
        public static void AttachOneShotCommandHandler(FrameworkElement element, RoutedEvent @event, RoutedEventHandler callback)
        {
            RoutedEventHandler handler = null;

            handler = (arg0, arg1) =>
            {
                element.RemoveHandler(@event, handler);

                callback(arg0, arg1);
            };

            element.AddHandler(@event, handler);
        }
Esempio n. 29
0
 /// <summary>
 /// 为FrameworkElement启动拖动功能
 /// </summary>
 /// <param name="controlToDrag">需要拖动功能的组件</param>
 /// <param name="dragHook">拖动锚点</param>
 /// <param name="isAbutCanDrag">是否肯定可被拖动(在组件相互遮盖的情况下标示是否强制拖动被遮盖组件)</param>
 public void Invest(FrameworkElement controlToDrag, FrameworkElement dragHook, bool isAbutCanDrag = true)
 {
     _leftBtnDown = new MouseButtonEventHandler(dragHook_MouseLeftButtonDown);
     _mouseMove   = new MouseEventHandler(dragHook_MouseMove);
     _leftBtnUp   = new MouseButtonEventHandler(dragHook_MouseLeftButtonUp);
     if (dragHook != null)
     {
         if (isAbutCanDrag)
         {
             dragHook.AddHandler(UIElement.MouseLeftButtonDownEvent, _leftBtnDown, true);
         }
         else
         {
             dragHook.MouseLeftButtonDown += _leftBtnDown;
         }
         dragHook.AddHandler(UIElement.MouseMoveEvent, _mouseMove, true);
         dragHook.AddHandler(UIElement.MouseLeftButtonUpEvent, _leftBtnUp, true);
     }
     _dragHook      = dragHook;
     _controlToDrag = controlToDrag;
     _translate     = TransformHelper.SetTransform <TranslateTransform>(_controlToDrag);
 }
Esempio n. 30
0
        static void OnEnableChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ScrollViewer scrollviewer = sender as ScrollViewer;

            if (scrollviewer != null && e.NewValue is bool &&
                scrollviewer.Content != null && scrollviewer.Content is FrameworkElement)
            {
                FrameworkElement fe = scrollviewer.Content as FrameworkElement;
                if ((bool)e.NewValue)
                {
                    SetStartPoint(scrollviewer, new Point(-1, -1));
                    fe.AddHandler(FrameworkElement.PreviewMouseDownEvent, mouseButtonDownHandle);
                    fe.AddHandler(FrameworkElement.PreviewMouseUpEvent, mouseButtonUpHandle);
                    fe.AddHandler(FrameworkElement.PreviewMouseMoveEvent, mouseMoveHandle);
                }
                else
                {
                    fe.RemoveHandler(FrameworkElement.PreviewMouseDownEvent, mouseButtonDownHandle);
                    fe.RemoveHandler(FrameworkElement.PreviewMouseUpEvent, mouseButtonUpHandle);
                    fe.RemoveHandler(FrameworkElement.PreviewMouseMoveEvent, mouseMoveHandle);
                }
            }
        }