Пример #1
0
 /// <summary>
 /// Sets the spacing mode of the element relative to the previous label/element group.
 /// </summary>
 /// <param name="element">The element to set.</param>
 /// <param name="spacingMode">The spacing mode to use.</param>
 public static void SetSpacingMode(FrameworkElement element, FormPanelSpacing spacingMode)
 {
     element.SetValue(SpacingModeProperty, spacingMode);
 }
Пример #2
0
        private void UpdateLayoutVertical()
        {
            ColumnDefinitionCollection columns = ColumnDefinitions;

            if (columns.Count == 0)
            {
                // For a vertical layout, we have three columns:
                // the Label, LabelSpacing, and the Control

                columns.Add(new ColumnDefinition()
                {
                    Width = new GridLength(0, GridUnitType.Auto)
                });
                columns.Add(new ColumnDefinition()
                {
                    Width = new GridLength(LabelSpacing, GridUnitType.Pixel)
                });
                columns.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            RowDefinitionCollection rows = RowDefinitions;

            rows.Clear();

            int regularSpacing = Spacing;
            int labelSpacing   = LabelSpacing;

            bool hasStretchingElement = false;

            bool spanColumns     = false;
            bool createNewRow    = true;
            bool addSpacing      = false;
            int  verticalSpacing = regularSpacing;

            HorizontalAlignment labelAlignment = HorizontalAlignment.Left;

            if (LabelAlignment == FormPanelLabelAlignment.Right)
            {
                labelAlignment = HorizontalAlignment.Right;
            }

            for (int i = 0; i < Children.Count; i++)
            {
                FrameworkElement element      = (FrameworkElement)Children[i];
                Label            labelElement = element as Label;

                // Create a new row if we know we need to create one or we
                // encountered a label (even if we weren't expecting one)
                if (createNewRow || ((labelElement != null) && (i != 0)))
                {
                    if (addSpacing && (i != 0))
                    {
                        FormPanelSpacing spacingMode = GetSpacingMode(element);

                        if (spacingMode != FormPanelSpacing.Ignore)
                        {
                            if (spacingMode == FormPanelSpacing.Extra)
                            {
                                verticalSpacing += verticalSpacing;
                            }
                            rows.Add(new RowDefinition()
                            {
                                Height = new GridLength(verticalSpacing, GridUnitType.Pixel)
                            });
                        }
                        addSpacing = false;
                    }
                    rows.Add(new RowDefinition()
                    {
                        Height = new GridLength(0, GridUnitType.Auto)
                    });
                }

                Grid.SetRow(element, rows.Count - 1);

                if (labelElement != null)
                {
                    if (GetLabelPosition(labelElement) == FormPanelLabelPosition.Top)
                    {
                        labelElement.HorizontalAlignment = HorizontalAlignment.Left;
                        Grid.SetColumnSpan(labelElement, 3);

                        spanColumns     = true;
                        createNewRow    = true;
                        verticalSpacing = labelSpacing;
                        addSpacing      = true;
                    }
                    else
                    {
                        labelElement.HorizontalAlignment = labelAlignment;
                        if (labelElement.VerticalAlignment != VerticalAlignment.Top)
                        {
                            labelElement.VerticalAlignment = VerticalAlignment.Center;
                        }

                        spanColumns = false;

                        createNewRow    = false;
                        verticalSpacing = regularSpacing;
                    }
                }
                else
                {
                    if (spanColumns || (GetIsLabeled(element) == false))
                    {
                        Grid.SetColumnSpan(element, 3);
                        spanColumns = false;
                    }
                    else
                    {
                        Grid.SetColumn(element, 2);
                        if (Double.IsNaN(element.Width) == false)
                        {
                            element.HorizontalAlignment = HorizontalAlignment.Left;
                        }
                    }

                    if ((hasStretchingElement == false) && GetIsStretched(element))
                    {
                        rows[rows.Count - 1].Height = new GridLength(1, GridUnitType.Star);
                        hasStretchingElement        = true;
                        element.VerticalAlignment   = VerticalAlignment.Stretch;
                    }
                    else
                    {
                        element.VerticalAlignment = VerticalAlignment.Center;
                    }

                    createNewRow    = true;
                    verticalSpacing = regularSpacing;
                    addSpacing      = true;
                }
            }

            if (hasStretchingElement == false)
            {
                // Add the final filler row
                rows.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
        }
Пример #3
0
 /// <summary>
 /// Sets the spacing mode of the element relative to the previous label/element group.
 /// </summary>
 /// <param name="element">The element to set.</param>
 /// <param name="spacingMode">The spacing mode to use.</param>
 public static void SetSpacingMode(FrameworkElement element, FormPanelSpacing spacingMode)
 {
     element.SetValue(SpacingModeProperty, spacingMode);
 }