Esempio n. 1
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = this.DataContext as DesignerItem;
            DesignerCanvas designer     = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                // we only move DesignerItems
                var designerItems = from item in designer.SelectedItems
                                    where item is DesignerItem
                                    select item;

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
                }

                double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                double deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    if (double.IsNaN(left))
                    {
                        left = 0;
                    }
                    if (double.IsNaN(top))
                    {
                        top = 0;
                    }

                    Canvas.SetLeft(item, left + deltaHorizontal);
                    Canvas.SetTop(item, top + deltaVertical);
                }

                designer.InvalidateMeasure();
                e.Handled = true;
            }
        }
Esempio n. 2
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            CircuitPart    circuitPart = this.DataContext as CircuitPart;
            DesignerCanvas designer    = VisualTreeHelper.GetParent(circuitPart) as DesignerCanvas;

            if (circuitPart != null && designer != null && circuitPart.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                // we only move CircuitPart
                var circuitParts = designer.SelectionService.CurrentSelection.OfType <CircuitPart>();

                foreach (CircuitPart item in circuitParts)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
                }

                double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                double deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                foreach (CircuitPart item in circuitParts)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    if (double.IsNaN(left))
                    {
                        left = 0;
                    }
                    if (double.IsNaN(top))
                    {
                        top = 0;
                    }

                    Canvas.SetLeft(item, left + deltaHorizontal);
                    Canvas.SetTop(item, top + deltaVertical);
                }

                designer.InvalidateMeasure();
                e.Handled = true;
            }
        }
Esempio n. 3
0
        private void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (designer == null)
            {
                return;
            }
            var container = designer.ItemContainerGenerator.ContainerFromItem(destItem) as UIElement;

            if (container == null)
            {
                return;
            }
            if (!instantPreview)
            {
                var tf    = TransformToAncestor((Visual)Parent);
                var delta = new Point(e.HorizontalChange, e.VerticalChange);
                delta = tf.Transform(delta);
                var minLeft = double.MaxValue;
                var minTop  = double.MaxValue;
                foreach (var item in designer.SelectedItems.OfType <IBoxCanvasItem>())
                {
                    var left = item.Left;
                    var top  = item.Top;
                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
                }
                var deltaHorizontal = Math.Max(-minLeft, delta.X);
                var deltaVertical   = Math.Max(-minTop, delta.Y);
                foreach (var item in designer.SelectedItems.OfType <IBoxCanvasItem>())
                {
                    if (item == destItem)
                    {
                        continue;
                    }
                    item.NotifyUserDragging(deltaHorizontal, deltaVertical);
                    item.Left += deltaHorizontal;
                    item.Top  += deltaVertical;
                }
            }
            foreach (var item in designer.SelectedItems)
            {
                item.NotifyUserDraggingStarted();
            }
            designer.InvalidateMeasure();
        }