Esempio n. 1
0
        public void Resize(int col, int row)
        {
            Tools.GetActualLength(CellMargin, ActualWidth);

            if (Col == col && Row == row)
            {
                return;
            }
            else
            {
                Col = col;
                Row = row;
            }
            var col_percent = 1.0 / col;

            ContainerGrid.ColumnDefinitions.Clear();
            var total = col * row;

            for (int i = 0; i < col; i++)
            {
                ContainerGrid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(col_percent, GridUnitType.Star)
                });
            }

            var row_percent = 1.0 / row;

            ContainerGrid.RowDefinitions.Clear();
            for (int i = 0; i < row; i++)
            {
                ContainerGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(row_percent, GridUnitType.Star)
                });
            }
            ContainerGrid.UpdateLayout();
            InteractionVisuals.Clear();
            if (GlobalInteraction != null)
            {
                InteractionVisuals.Add(GlobalInteraction);
                GlobalInteraction.ParentElement = this;
            }

            var index = 0;

            ContainersUsed.Clear();
            ContainersUnused.Clear();
            foreach (var item in Containers)
            {
                if (index >= total)
                {
                    ContainersUnused.Add(item);
                    continue;
                }
                var c = item.DrawingCanvas;
                ContainersUsed.Add(item);
                c.Col = index % col;
                c.Row = index / col;
                SetColumn(item, c.Col);
                SetRow(item, c.Row);
                SetColumnSpan(item, 1);
                SetRowSpan(item, 1);
                if (c.Id == -1)
                {
                    c.Id = IdGenerater.GenerateId();
                }
                if (GlobalInteraction != null)
                {
                    GlobalInteraction.DataSources.Clear();
                    GlobalInteraction.DataSources.Add(c.Id, c.DataSource);
                    GlobalInteraction.DependencyContainers.Clear();
                    GlobalInteraction.DependencyContainers.Add(c.Id, item);
                    c.InteractionCanvas = GlobalInteraction;
                }
                else
                {
                    // 送默认AxisInteractionCanvas
                    var interaction2 = item.InteractionCanvas;
                    if (interaction2 != null)
                    {
                        interaction2.DependencyContainers.Clear();
                        interaction2.DependencyContainers.Add(c.Id, item);
                        interaction2.DataSources.Clear();
                        interaction2.DataSources.Add(c.Id, c.DataSource);
                        interaction2.ParentElement = item;
                        c.InteractionCanvas        = interaction2;
                        item.DisableInteraction();
                        item.EnableInteraction();
                        InteractionVisuals.Add(interaction2);
                    }
                }
                index++;
            }
        }