Example #1
0
        partial void InitConstruction()
        {
            this.InitializeComponent();

            var param = CSParam as CommentConstructParam;

            this.Width  = param.Width;
            this.Height = param.Height;

            CommentText.SetBinding(TextBlock.TextProperty, new Binding("Comment")
            {
                Source = param
            });
            ContentGrid.SetBinding(Grid.BackgroundProperty, new Binding("BlendBrush")
            {
                Source = this
            });

            this.BlendBrush = new SolidColorBrush(Color.FromArgb(param.Color.A, param.Color.R, param.Color.G, param.Color.B));

            int deepestZIndex = -10;

            if (HostNodesContainer != null && !HostNodesContainer.IsLoading)
            {
                bool   has = false;
                double left = double.MaxValue, right = double.MinValue, top = double.MaxValue, bottom = double.MinValue;
                // 创建时包围所有选中的节点
                for (int i = 0; i < HostNodesContainer.CtrlNodeList.Count; i++)
                {
                    var node = HostNodesContainer.CtrlNodeList[i];
                    if (!node.Selected)
                    {
                        continue;
                    }
                    var loc     = node.GetLocation();
                    var nRight  = loc.X + node.GetWidth();
                    var nBottom = loc.Y + node.GetHeight();

                    var zIndex = Canvas.GetZIndex(node);
                    if (deepestZIndex > zIndex)
                    {
                        deepestZIndex = zIndex;
                    }

                    if (left > loc.X)
                    {
                        left = loc.X;
                    }
                    if (top > loc.Y)
                    {
                        top = loc.Y;
                    }
                    if (right < nRight)
                    {
                        right = nRight;
                    }
                    if (bottom < nBottom)
                    {
                        bottom = nBottom;
                    }

                    has = true;
                }

                if (has)
                {
                    mCreateX     = left - 50;
                    mCreateY     = top - 100;
                    this.Width   = right + 50 - mCreateX;
                    this.Height  = bottom + 50 - mCreateY;
                    param.Width  = this.Width;
                    param.Height = this.Height;
                }
            }
            Canvas.SetZIndex(this, deepestZIndex - 1);
        }