Ejemplo n.º 1
0
        private void UpdateRowHeight(DependencyObject child)
        {
            object objHeight = child.GetValue(AutoGrid.RowHeightProperty);

            if (AutoGrid.WasSet(objHeight))
            {
                GridLength    rowHeight = (GridLength)objHeight;
                RowDefinition row       = this.RowDefinitions[(int)child.GetValue(Grid.RowProperty)];
                if (rowHeight != row.Height)
                {
                    row.Height = rowHeight;
                }
            }
            else
            {
                FrameworkElement fe = child as FrameworkElement;
                if (fe != null && !(fe.MaxHeight < double.MaxValue || 0 < fe.Height))
                {
                    TextBox textBox;
                    // Do not replace ListBox, ListView,... with ItemsControl. As too many of controls are ItemsControls.
                    if (fe is GroupBox || fe is RichTextBox || fe is TreeView || fe is ListView || fe is ListBox || fe is DataGrid ||
                        (textBox = fe as TextBox) != null && textBox.AcceptsReturn && !(1 < textBox.MinLines || textBox.MaxLines < int.MaxValue)
                        )
                    {
                        RowDefinition row = this.RowDefinitions[(int)child.GetValue(Grid.RowProperty)];
                        if (row.Height == GridLength.Auto)
                        {
                            row.Height = new GridLength(1, GridUnitType.Star);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static int DesiredColumn(UIElement child)
        {
            object column = child.ReadLocalValue(Grid.ColumnProperty);

            if (AutoGrid.WasSet(column))
            {
                return((int)column);
            }
            return(-1);
        }
Ejemplo n.º 3
0
        private int DefineColumns()
        {
            Debug.Assert(this.ColumnDefinitions.Count == 0);
            Debug.Assert(this.RowDefinitions.Count == 0);
            int count = 0;

            foreach (GridLength gridLength in AutoGrid.ParseColumnWidths(this.ColumnWidths))
            {
                this.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = gridLength
                });
                count++;
            }
            return(count);
        }
Ejemplo n.º 4
0
 private void LinkLabels()
 {
     for (int i = 0; i < this.Children.Count; i++)
     {
         UIElement child = this.Children[i];
         if (child is Label label && i + 1 < this.Children.Count && !AutoGrid.WasSet(label.Target) && label.GetBindingExpression(Label.TargetProperty) == null)
         {
             UIElement next = this.Children[i + 1];
             if (!(next is Panel) && !(next is GroupBox) && next.Focusable &&
                 (int)label.GetValue(Grid.RowProperty) == (int)next.GetValue(Grid.RowProperty) &&
                 (int)label.GetValue(Grid.ColumnProperty) == 0 &&
                 (int)next.GetValue(Grid.ColumnProperty) == 1
                 )
             {
                 label.Target = next;
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void PlaceChildren()
        {
            int maxColumns = this.DefineColumns();
            int column     = 0;
            int row        = 0;

            foreach (UIElement child in this.Children)
            {
                int desiredColumn = AutoGrid.DesiredColumn(child);
                Debug.Assert(-1 <= desiredColumn && desiredColumn < maxColumns);
                if (0 <= desiredColumn)
                {
                    if (desiredColumn < column)
                    {
                        row++;
                    }
                    column = desiredColumn;
                }
                else if (maxColumns <= column)
                {
                    column = 0;
                    row++;
                }
                if (this.RowDefinitions.Count <= row)
                {
                    this.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }
                if (desiredColumn != column)
                {
                    child.SetValue(Grid.ColumnProperty, column);
                }
                child.SetValue(Grid.RowProperty, row);
                int columnSpan = (int)child.GetValue(Grid.ColumnSpanProperty);
                Debug.Assert(column + columnSpan <= maxColumns);
                column += columnSpan;
                this.UpdateRowHeight(child);
            }
        }