Ejemplo n.º 1
0
 public ToolBoxGrid()
 {
     SizeChanged +=
         delegate
     {
         var lastRowDefinition = RowDefinitions.Last();
         var rowsHeight        = RowDefinitions.Sum(rd => rd.ActualHeight);
         lastRowDefinition.Height = new GridLength(Math.Max(LastRowMinHeight, ActualHeight - rowsHeight + lastRowDefinition.ActualHeight));
     };
 }
Ejemplo n.º 2
0
        protected override void OnInitialized(EventArgs e0)
        {
            base.OnInitialized(e0);
            var parent = Parent as FrameworkElement;

            parent.SizeChanged +=
                (sender, e) =>
            {
                var heightDiff = e.NewSize.Height - e.PreviousSize.Height;
                if (heightDiff < 0)
                {
                    RowDefinitions.Last().Height = new GridLength(LastRowMinHeight);
                }
            };
        }
Ejemplo n.º 3
0
        private void Initialize()
        {
            if (!_hasLoaded && !String.IsNullOrWhiteSpace(Rows))
            {
                var heights = GridLengthParser.FromString(Rows);
                foreach (var height in heights)
                {
                    RowDefinitions.Add(new RowDefinition {
                        Height = height
                    });
                }
            }

            if (!_hasLoaded && !String.IsNullOrWhiteSpace(Columns))
            {
                var widths = GridLengthParser.FromString(Columns);
                foreach (var width in widths)
                {
                    ColumnDefinitions.Add(new ColumnDefinition {
                        Width = width
                    });
                }
            }

            _hasLoaded = true;

            for (int i = ColumnDefinitions.Count; i < NumColumns; i++)
            {
                ColumnDefinitions.Add(new ColumnDefinition {
                    Width = ColumnWidth
                });
            }

            if (RowDefinitions.Count == 0)
            {
                RowDefinitions.Add(new RowDefinition {
                    Height = RowHeight
                });
            }

            var currentColumn = 0;
            var currentRow    = 0;
            var columnCount   = ColumnDefinitions.Count == 0 ? 1 : ColumnDefinitions.Count; //if we have no col defs we have one col.

            foreach (var child in Children)
            {
                if (!GetAutoplace((UIElement)child))
                {
                    continue;
                }

                var childColumnSpan = GetColumnSpan((FrameworkElement)child);
                var childRowSpan    = GetRowSpan((FrameworkElement)child);
                var placed          = false;

                while (!placed)
                {
                    var cellsLeft = columnCount - currentColumn;

                    if (currentColumn != 0 && cellsLeft < childColumnSpan) //can't fit this row
                    {
                        currentRow    = GetNextRowAndAddIfRequired(currentRow);
                        currentColumn = 0;
                        continue;
                    }

                    if (IsFull(currentRow, currentColumn, childColumnSpan))
                    {
                        currentColumn++;
                        continue;
                    }

                    SetColumn((FrameworkElement)child, currentColumn);
                    SetRow((FrameworkElement)child, currentRow);
                    AddSpannedCells(currentRow, currentColumn, childRowSpan, childColumnSpan);
                    currentColumn += childColumnSpan;
                    placed         = true;
                }
            }

            if (StretchLastRow)
            {
                RowDefinitions.Last().Height = new GridLength(1, GridUnitType.Star);
            }
        }