Exemplo 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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static int DesiredColumn(UIElement child)
        {
            object column = child.ReadLocalValue(Grid.ColumnProperty);

            if (AutoGrid.WasSet(column))
            {
                return((int)column);
            }
            return(-1);
        }
Exemplo n.º 3
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;
             }
         }
     }
 }