Пример #1
0
        void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem designerItem = this.DataContext as DesignerItem;
            MyCanvas     designer     = VisualTreeHelper.GetParent(designerItem) as MyCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft, minTop, minDeltaHorizontal, minDeltaVertical;
                double dragDeltaVertical, dragDeltaHorizontal;
                var    selectedDesignerItems = from item in designer.SelectedItems
                                               where item is DesignerItem
                                               select item;

                CalculateDragLimits(selectedDesignerItems, out minLeft, out minTop,
                                    out minDeltaHorizontal, out minDeltaVertical);

                foreach (DesignerItem item in selectedDesignerItems)
                {
                    if (item != null)
                    {
                        switch (base.VerticalAlignment)
                        {
                        case VerticalAlignment.Bottom:
                            dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
                            item.Height       = item.ActualHeight - dragDeltaVertical;
                            break;

                        case VerticalAlignment.Top:
                            double top = Canvas.GetTop(item);
                            dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
                            Canvas.SetTop(item, top + dragDeltaVertical);
                            item.Height = item.ActualHeight - dragDeltaVertical;
                            break;

                        default:
                            break;
                        }

                        switch (base.HorizontalAlignment)
                        {
                        case HorizontalAlignment.Left:
                            double left = Canvas.GetLeft(item);
                            dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
                            Canvas.SetLeft(item, left + dragDeltaHorizontal);
                            item.Width = item.ActualWidth - dragDeltaHorizontal;
                            break;

                        case HorizontalAlignment.Right:
                            dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
                            item.Width          = item.ActualWidth - dragDeltaHorizontal;
                            break;

                        default:
                            break;
                        }
                    }
                }
                e.Handled = true;
            }
        }
Пример #2
0
 /// <summary>
 /// 鼠标移动事件
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (e.LeftButton != MouseButtonState.Pressed)
     {
         this.dragStartPoint = null;
     }
     if (this.dragStartPoint.HasValue)
     {
         //创建连接装饰器
         MyCanvas canvas = GetDesignerCanvas(this);
         if (canvas != null)
         {
             AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas);
             if (adornerLayer != null)
             {
                 ConnectorAdorner adorner = new ConnectorAdorner(canvas, this);
                 if (adorner != null)
                 {
                     adornerLayer.Add(adorner);
                     e.Handled = true;
                 }
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// 鼠标单击的事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            MyCanvas designer = VisualTreeHelper.GetParent(this) as MyCanvas;

            // designer.Focus();
            if (designer != null)
            {
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                {
                    if (this.IsSelected)
                    {
                        this.IsSelected = false;
                        designer.SelectedItems.Remove(this);
                    }
                    else
                    {
                        this.IsSelected = true;
                        designer.SelectedItems.Add(this);
                    }
                }
                else if (!this.IsSelected)
                {
                    foreach (ISelectable item in designer.SelectedItems)
                    {
                        item.IsSelected = false;
                    }

                    designer.SelectedItems.Clear();
                    this.IsSelected = true;
                    designer.SelectedItems.Add(this);
                }
            }
            e.Handled = false;
        }
Пример #4
0
 public RubberbandAdorner(MyCanvas designerCanvas, Point? dragStartPoint)
     : base(designerCanvas)
 {
     this.designerCanvas = designerCanvas;
     this.startPoint = dragStartPoint;
     rubberbandPen = new Pen(Brushes.LightSlateGray, 1);
     rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
 }
Пример #5
0
 public RubberbandAdorner(MyCanvas designerCanvas, Point?dragStartPoint)
     : base(designerCanvas)
 {
     this.designerCanvas     = designerCanvas;
     this.startPoint         = dragStartPoint;
     rubberbandPen           = new Pen(Brushes.LightSlateGray, 1);
     rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
 }
Пример #6
0
        // 当布局更改时更行相对位置
        void Connector_LayoutUpdated(object sender, EventArgs e)
        {
            MyCanvas designer = GetDesignerCanvas(this);

            if (designer != null)
            {
                this.Position = this.TransformToAncestor(designer).Transform(new Point(this.Width / 2, this.Height / 2));
            }
        }
Пример #7
0
 public ConnectorAdorner(MyCanvas designer, Connector sourceConnector)
     : base(designer)
 {
     this.designerCanvas  = designer;
     this.sourceConnector = sourceConnector;
     drawingPen           = new Pen(Brushes.LightSlateGray, 1);
     drawingPen.LineJoin  = PenLineJoin.Round;
     this.Cursor          = Cursors.Cross;
 }
Пример #8
0
 public ConnectorAdorner(MyCanvas designer, Connector sourceConnector)
     : base(designer)
 {
     this.designerCanvas = designer;
     this.sourceConnector = sourceConnector;
     drawingPen = new Pen(Brushes.LightSlateGray, 1);
     drawingPen.LineJoin = PenLineJoin.Round;
     this.Cursor = Cursors.Cross;
 }
Пример #9
0
        internal ConnectorInfo GetInfo()
        {
            ConnectorInfo info = new ConnectorInfo();

            info.DesignerItemLeft = MyCanvas.GetLeft(this.ParentDesignerItem);
            info.DesignerItemTop  = MyCanvas.GetTop(this.ParentDesignerItem);
            info.DesignerItemSize = new Size(this.ParentDesignerItem.ActualWidth, this.ParentDesignerItem.ActualHeight);
            info.Orientation      = this.Orientation;
            info.Position         = this.Position;
            return(info);
        }
Пример #10
0
        /// <summary>
        /// 鼠标拖拽触发的事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            this.Focus();
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                DesignerItem newItem = null;
                Object       content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                if (content != null)
                {
                    int maxValue = value++;
                    newItem         = new DesignerItem(TradeCode, maxValue.ToString());
                    newItem.Content = content;
                    var lbl = content as Label;
                    if (lbl != null)
                    {
                        newItem.ToolTip = lbl.ToolTip;
                    }

                    Point position = e.GetPosition(this);
                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        MyCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        MyCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        MyCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        MyCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }

                    this.Children.Add(newItem);

                    //更新选中项
                    foreach (ISelectable item in this.SelectedItems)
                    {
                        item.IsSelected = false;
                    }
                    SelectedItems.Clear();
                    newItem.IsSelected = true;
                    this.SelectedItems.Add(newItem);
                }

                e.Handled = true;
            }
        }
Пример #11
0
        /// <summary>
        /// 鼠标单击事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            MyCanvas canvas = GetDesignerCanvas(this);

            if (canvas != null)
            {
                // 相对于DesignerCanvas的位置
                this.dragStartPoint = new Point?(e.GetPosition(canvas));
                e.Handled           = true;
            }
        }
Пример #12
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem designerItem = this.DataContext as DesignerItem;
            MyCanvas     designer     = VisualTreeHelper.GetParent(designerItem) as MyCanvas;

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

                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;
            }
        }
Пример #13
0
        public ConnectionAdorner(MyCanvas designer, Connection connection)
            : base(designer)
        {
            this.designerCanvas = designer;
            adornerCanvas       = new Canvas();
            this.visualChildren = new VisualCollection(this);
            this.visualChildren.Add(adornerCanvas);

            this.connection = connection;
            this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged);

            InitializeDragThumbs();

            drawingPen          = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;
        }
Пример #14
0
        public ConnectionAdorner(MyCanvas designer, Connection connection)
            : base(designer)
        {
            this.designerCanvas = designer;
            adornerCanvas = new Canvas();
            this.visualChildren = new VisualCollection(this);
            this.visualChildren.Add(adornerCanvas);

            this.connection = connection;
            this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged);

            InitializeDragThumbs();

            drawingPen = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;
        }
Пример #15
0
        private void ShowAdorner()
        {
            //创建一个ConnectionAdorner装饰器
            if (this.connectionAdorner == null)
            {
                MyCanvas designer = VisualTreeHelper.GetParent(this) as MyCanvas;

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer);
                if (adornerLayer != null)
                {
                    this.connectionAdorner = new ConnectionAdorner(designer, this);
                    adornerLayer.Add(this.connectionAdorner);
                }
            }
            this.connectionAdorner.Visibility = Visibility.Visible;
        }
Пример #16
0
 /// <summary>
 /// 销毁线条
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Connection_Unloaded(object sender, RoutedEventArgs e)
 {
     source.PropertyChanged -= new PropertyChangedEventHandler(OnConnectorPositionChanged);
     sink.PropertyChanged   -= new PropertyChangedEventHandler(OnConnectorPositionChanged);
     // remove adorner
     if (this.connectionAdorner != null)
     {
         MyCanvas designer = VisualTreeHelper.GetParent(this) as MyCanvas;
         if (designer == null)
         {
             return;
         }
         AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(designer);
         if (adornerLayer != null)
         {
             adornerLayer.Remove(this.connectionAdorner);
             this.connectionAdorner = null;
         }
     }
 }
Пример #17
0
        /// <summary>
        /// 鼠标按下事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);
            MyCanvas designer = VisualTreeHelper.GetParent(this) as MyCanvas;
            //designer.Focus();
            var lbl = (this.Content) as Label;

            lbl.IsHitTestVisible = false;
            lbl.Focusable        = false;
            if (designer != null)
            {
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                {
                    if (this.IsSelected)
                    {
                        this.IsSelected = false;
                        designer.SelectedItems.Remove(this);
                    }
                    else
                    {
                        this.IsSelected = true;
                        designer.SelectedItems.Add(this);
                    }
                }
                else if (!this.IsSelected)
                {
                    foreach (ISelectable item in designer.SelectedItems)
                    {
                        item.IsSelected = false;
                    }

                    designer.SelectedItems.Clear();
                    this.IsSelected = true;
                    designer.SelectedItems.Add(this);
                }
            }
            designer.Focus();

            e.Handled = false;
        }
Пример #18
0
        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            MyCanvas designer  = VisualTreeHelper.GetParent(this) as MyCanvas;
            var      tradeFlow = "";

            designer.Save().ForEach(x =>
            {
                if (x.FlowCode == this.CurrentSerialNumber)
                {
                    tradeFlow = x.Trade_Flow;
                }
            });

            if (designer != null)
            {
                if (SubRelList == null)
                {
                    SubRelList = new List <SubRel>();
                }
                Show(this.Name, ComponentCode, CurrentSerialNumber, tradeFlow, ConditionList, SubRelList);
            }
        }
Пример #19
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="canvas">canvas对象</param>
 public SelectionService(MyCanvas canvas)
 {
     this.designerCanvas = canvas;
 }
Пример #20
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="canvas">canvas对象</param>
 public SelectionService(MyCanvas canvas)
 {
     this.designerCanvas = canvas;
 }