コード例 #1
0
ファイル: DragThumb.cs プロジェクト: bakacaptain/intocps-ui
        private void OnDragDelta(object sender, DragDeltaEventArgs e)
        {
            var block   = DataContext as BlockViewModel;
            var diagram = VisualTreeHelper.GetParent(block) as DiagramCanvas;

            if (block != null && diagram != null && block.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                // only move blocks
                var blocks = from element in diagram.SelectedElements
                             where element is BlockViewModel
                             select element;

                // Sets left and top position
                foreach (BlockViewModel element in blocks)
                {
                    var left = Canvas.GetLeft(element);
                    var top  = Canvas.GetTop(element);

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

                // Calculate delta movement
                var deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                var deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                // Set moved postion
                foreach (BlockViewModel element in blocks)
                {
                    var left = Canvas.GetLeft(element);
                    var top  = Canvas.GetTop(element);

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

                    element.BlockModel.Position = new Point(left + deltaHorizontal, top + deltaVertical);
                    DiagramCanvas.UpdatePosition(element);
                }

                diagram.InvalidateMeasure();
                e.Handled = true;
            }
        }
コード例 #2
0
        private void OnModelChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Height")
            {
                Height = blockModel.Height;
            }
            if (e.PropertyName == "Width")
            {
                Width = blockModel.Width;
            }

            DiagramCanvas.UpdatePosition(this);
        }