コード例 #1
0
        /// <summary>
        /// 从可视树上获取某个元素的外层 DesignerItemContainer。
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static DesignerItemContainer GetItemContainer(DependencyObject element)
        {
            DesignerItemContainer designerItem = null;

            DependencyObject parent = element;

            while (true)
            {
                parent = VisualTreeHelper.GetParent(parent);
                if (parent == null)
                {
                    break;
                }

                designerItem = parent as DesignerItemContainer;
                if (designerItem != null)
                {
                    break;
                }

                //如果已经找到 DesignerCanvas,则退出。
                if (parent is DesignerCanvas)
                {
                    break;
                }
            }

            return(designerItem);
        }
コード例 #2
0
        private static ConnectorInfo GetConnectorInfo(DesignerItemContainer item, Point relative)
        {
            var info = new ConnectorInfo();

            info.DesignerItemRect = item.GetRect();
            info.Position         = RectAlgorithm.GetRectAbsolute(info.DesignerItemRect, relative);
            return(info);
        }
コード例 #3
0
ファイル: DragThumb.cs プロジェクト: yungtau/oea
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            var designerItem = DesignerItemContainer.GetItemContainer(this);

            if (designerItem != null && designerItem.IsSelected)
            {
                var designer = DesignerCanvas.GetOwnerCanvas(designerItem);
                if (designer != null)
                {
                    //只移动 DesignerItem
                    var designerItems = designer.SelectedItems.OfType <DesignerItemContainer>();

                    //以下代码不知何意,暂留。
                    //double minLeft = double.MaxValue;
                    //double minTop = double.MaxValue;

                    //foreach (var item in designerItems)
                    //{
                    //    double left = GetDouble(item, Canvas.LeftProperty);
                    //    double top = GetDouble(item, Canvas.TopProperty);

                    //    minLeft = Math.Min(left, minLeft);
                    //    minTop = Math.Min(top, minTop);
                    //}

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

                    double deltaHorizontal = e.HorizontalChange;
                    double deltaVertical   = e.VerticalChange;

                    foreach (var item in designerItems)
                    {
                        double left = GetDouble(item, Canvas.LeftProperty);
                        double top  = GetDouble(item, Canvas.TopProperty);

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

                    designer.InvalidateMeasure();

                    e.Handled = true;
                }
            }
        }
コード例 #4
0
ファイル: DesignerCanvas.cs プロジェクト: yungtau/oea
        internal protected virtual void OnDragLineCompleted(DesignerItemContainer source, DesignerItemContainer sink)
        {
            //默认实现如下:
            ////从 0 开始添加,可以保证连接显示在元素之后。
            //this.Children.Insert(0, new Connection
            //{
            //    Source = source,
            //    Sink = sink
            //});

            var handler = this.DragLineCompleted;

            if (handler != null)
            {
                handler(this, new CanvasDragLineCompletedEventArgs(source, sink));
            }
        }
コード例 #5
0
ファイル: ConnectionAdorner.cs プロジェクト: yungtau/oea
        void thumbDragThumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            this.Cursor          = Cursors.Cross;
            this.HitDesignerItem = null;
            this._pathGeometry   = null;

            if (sender == _sourceDragThumb)
            {
                _startItem    = _connection.Sink;
                _draggingItem = _connection.Source;
            }
            else if (sender == _sinkDragThumb)
            {
                _startItem    = _connection.Source;
                _draggingItem = _connection.Sink;
            }
        }
コード例 #6
0
ファイル: ConnectorAdorner.cs プロジェクト: yungtau/oea
        private void HitTesting(Point hitPoint)
        {
            var hitObject = _canvas.InputHitTest(hitPoint) as DependencyObject;

            while (hitObject != null && hitObject != _connector.ParentDesignerItem)
            {
                if (hitObject is DesignerCanvas)
                {
                    break;
                }

                if (hitObject is DesignerItemContainer)
                {
                    HitDesignerItem = hitObject as DesignerItemContainer;
                    return;
                }

                hitObject = VisualTreeHelper.GetParent(hitObject);
            }

            HitDesignerItem = null;
        }
コード例 #7
0
ファイル: DesignerCanvas.cs プロジェクト: yungtau/oea
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            var dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

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

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

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

                    this.Children.Add(newItem);

                    this.AddSelection(true, newItem);
                }

                e.Handled = true;
            }
        }
コード例 #8
0
ファイル: DesignerCanvas.cs プロジェクト: 569550384/Rafy
 public CanvasDragLineCompletedEventArgs(DesignerItemContainer source, DesignerItemContainer sink)
 {
     this.Source = source;
     this.Sink = sink;
 }
コード例 #9
0
ファイル: DesignerCanvas.cs プロジェクト: 569550384/Rafy
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            var dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                var content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));
                if (content != null)
                {
                    var newItem = new DesignerItemContainer();
                    newItem.Content = content;

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

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

                    this.Children.Add(newItem);

                    this.AddSelection(true, newItem);
                }

                e.Handled = true;
            }
        }
コード例 #10
0
ファイル: DesignerCanvas.cs プロジェクト: 569550384/Rafy
        protected internal virtual void OnDragLineCompleted(DesignerItemContainer source, DesignerItemContainer sink)
        {
            //默认实现如下:
            ////从 0 开始添加,可以保证连接显示在元素之后。
            //this.Children.Insert(0, new Connection
            //{
            //    Source = source,
            //    Sink = sink
            //});

            var handler = this.DragLineCompleted;
            if (handler != null) handler(this, new CanvasDragLineCompletedEventArgs(source, sink));
        }
コード例 #11
0
ファイル: ModelingDesigner.cs プロジェクト: 569550384/Rafy
        private void AddItemIntoCanvas(BlockControl block)
        {
            var container = new DesignerItemContainer();
            container.Content = block;
            block.Container = container;
            SetComponent(container, block);

            //应用样式
            var containerStyle = this.BlockContainerStyle;
            if (containerStyle != null) container.Style = containerStyle;

            container.DataContext = block;
            container.SetBinding(Canvas.LeftProperty, new Binding { Path = new PropertyPath(BlockControl.LeftProperty), Mode = BindingMode.TwoWay });
            container.SetBinding(Canvas.TopProperty, new Binding { Path = new PropertyPath(BlockControl.TopProperty), Mode = BindingMode.TwoWay });

            _canvas.Children.Add(container);
        }
コード例 #12
0
ファイル: Connection.cs プロジェクト: 569550384/Rafy
 private static ConnectorInfo GetConnectorInfo(DesignerItemContainer item, Point relative)
 {
     var info = new ConnectorInfo();
     info.DesignerItemRect = item.GetRect();
     info.Position = RectAlgorithm.GetRectAbsolute(info.DesignerItemRect, relative);
     return info;
 }
コード例 #13
0
ファイル: DesignerCanvas.cs プロジェクト: yungtau/oea
 public CanvasDragLineCompletedEventArgs(DesignerItemContainer source, DesignerItemContainer sink)
 {
     this.Source = source;
     this.Sink   = sink;
 }
コード例 #14
0
ファイル: ConnectionAdorner.cs プロジェクト: 569550384/Rafy
        void thumbDragThumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            this.Cursor = Cursors.Cross;
            this.HitDesignerItem = null;
            this._pathGeometry = null;

            if (sender == _sourceDragThumb)
            {
                _startItem = _connection.Sink;
                _draggingItem = _connection.Source;
            }
            else if (sender == _sinkDragThumb)
            {
                _startItem = _connection.Source;
                _draggingItem = _connection.Sink;
            }
        }
コード例 #15
0
ファイル: ConnectionAdorner.cs プロジェクト: 569550384/Rafy
        void thumbDragThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (_changeTarget)
            {
                var hitted = this.HitDesignerItem;
                if (hitted != null)
                {
                    if (_connection.Sink == _draggingItem)
                    {
                        _connection.Sink = hitted;
                    }
                    else
                    {
                        _connection.Source = hitted;
                    }

                    this.HitDesignerItem = null;
                }

                _connection.StrokeDashArray = _rawStrokeDashArray;

                _changeTarget = false;
            }

            this._pathGeometry = null;

            this.InvalidateVisual();
        }
コード例 #16
0
ファイル: ConnectionAdorner.cs プロジェクト: 569550384/Rafy
        private void HitTesting(Point hitPoint)
        {
            var hitObject = _designerCanvas.InputHitTest(hitPoint) as DependencyObject;
            while (hitObject != null && hitObject != _startItem)
            {
                if (hitObject is DesignerCanvas) break;

                if (hitObject is DesignerItemContainer)
                {
                    HitDesignerItem = hitObject as DesignerItemContainer;
                    return;
                }

                hitObject = VisualTreeHelper.GetParent(hitObject);
            }

            HitDesignerItem = null;
        }