Example #1
0
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            if (e.OriginalSource.GetType() == typeof(RouteItem))
            {
                Point position = e.GetPosition(this);
                // To prevent Mouse "hang" error, release Adorner object if one constructed
                if (_adorner != null)
                {
                    AdornerLayer.GetAdornerLayer(_adorner.AdornedElement).Remove(_adorner);
                }
                // Initialize new Adorner object
                _adorner = new AdornerDrawing(e.OriginalSource as UIElement)
                {
                    StartPoint = position
                };

                e.Handled = true;
            }
        }
Example #2
0
        private void DragFinished(bool cancel)
        {
            //Release Mouse
            Mouse.Capture(null);
            // Remove adorner object from rendering layer
            AdornerLayer.GetAdornerLayer(_adorner.AdornedElement).Remove(_adorner);

            if (_adorner.IsDragStarted && cancel == false)
            {
                //Move object to new position
                if (_adorner.OriginalSource is RouteItem rt)
                {
                    rt.SetBindingPoint(new Point(
                                           _adorner.StartPoint.X + _adorner.LeftOffset - _adorner.ActualWidth / 2,
                                           _adorner.StartPoint.Y + _adorner.TopOffset - _adorner.ActualHeight / 2));
                }

                _adorner = null;

                InvalidateVisual();
            }
        }