Example #1
0
        /// <summary>
        /// 拷贝一个新对象
        /// </summary>
        /// <returns></returns>
        public ContainerBox Clone()
        {
            var newBox = new ContainerBox();

            newBox.X               = this.X;
            newBox.Y               = this.Y;
            newBox.Width           = this.Width;
            newBox.Height          = this.Height;
            newBox.BorderThickness = this.BorderThickness;
            newBox.BorderBrush     = this.BorderBrush;
            newBox.BoxStatus       = this.BoxStatus;
            return(newBox);
        }
Example #2
0
        /// <summary>
        /// 更新箱区UI
        /// </summary>
        private void UpdateBoxAreaUI(int[,] boxs)
        {
            foreach (var item1 in listBorder)
            {
                foreach (var item2 in item1)
                {
                    rootCanvas.Children.Remove(item2);
                }
            }
            listBorder.Clear();


            var startPoint = new Point(100, 100);
            //得出箱在界面上的长宽
            var width  = 30;
            var height = 30;

            while (true)
            {
                maxBoxAreaPoint.X = width * (colCount + 2);
                maxBoxAreaPoint.Y = height * (rowCount + 1);

                startPoint.X = (rootCanvas.Width - maxBoxAreaPoint.X) / 2;
                startPoint.Y = rootCanvas.Height - maxBoxAreaPoint.Y;

                if (startPoint.X <= (leftCart.Margin.Left + leftCart.Width) || startPoint.Y < (minCart.Margin.Top + borderCart.Height + 50))
                {
                    width = height = width - 5;
                }
                else
                {
                    break;
                }
            }

            //初始化箱控件
            for (int row = 0; row < rowCount + 1; row++)
            {
                for (int col = 0; col < colCount + 2; col++)
                {
                    ContainerBox box = new ContainerBox();
                    box.Width  = width;
                    box.Height = height;
                    box.SetValue(Canvas.LeftProperty, startPoint.X + width * col);
                    box.SetValue(Canvas.TopProperty, startPoint.Y + height * row);
                    box.BorderThickness = new Thickness(1);
                    box.BorderBrush     = Brushes.Black;
                    if (col == 0 || col == colCount + 1)
                    {
                        if (row == 0)
                        {
                            continue;
                        }
                        box.Flag = true;
                        box.Text = rowCount - row + 1 + "";
                        if (col == 0)
                        {
                            box.HorizontalAlignment = HorizontalAlignment.Right;
                        }
                        else
                        {
                            box.HorizontalAlignment = HorizontalAlignment.Left;
                        }
                        box.BorderThickness = new Thickness(0);
                    }
                    else if (row == 0)
                    {
                        box.Flag = true;
                        box.Text = (leftToRight ? col : colCount - col + 1) + "";
                        box.VerticalAlignment = VerticalAlignment.Bottom;
                        box.BorderThickness   = new Thickness(0);
                    }
                    else
                    {
                        if (listBorder.Count <= row)
                        {
                            listBorder.Add(new List <ContainerBox>());
                        }
                        listBorder[row - 1].Add(box);
                    }
                    rootCanvas.Children.Add(box);

                    //初始化一个移动中的箱
                    if (movingBox == null)
                    {
                        var tmpBox = box.Clone();
                        tmpBox.BoxStatus = 2;
                        rootCanvas.Children.Add(tmpBox);
                        movingBox = tmpBox;

                        borderLifting.Width = movingBox.Width;
                    }
                }
            }

            //更新箱状态
            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < colCount; col++)
                {
                    var keyValue = ConvertToAdvanPoint(row, col);
                    listBorder[keyValue.Key][keyValue.Value].BoxStatus = boxs[row, col];
                }
            }

            lastBoxs = boxs;
        }