Aligning the contents of Silverlight fields

I simple form having some fields. So I decided to add some DataField with text fields and labels. The shortcuts are manageable and their length can be changed, and I need to place my text fields at the same distance from the left side. How can i do this?

alt text

+3
source share
3 answers

Try to install

tk:DataField.IsFieldGroup="True"

where tk is the namespace of the toolkit for the DataField; on the parent container of all field labels you must be the same width.

as

<Grid tk:DataField.IsFieldGroup="True">...

This will make the labels the same width as the longest label in the FieldGroup.

+2
source

You can use the grid

<Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Label Content="Label" Grid.Row="0" Grid.Column="0"/>
    <TextBox Grid.Row="0" Grid.Column="1"/>
    <Label Content="Long Label" Grid.Row="1" Grid.Column="0"/>
    <TextBox Grid.Row="1" Grid.Column="1"/>

+1

:

  void MyControl_LayoutUpdated(object sender, EventArgs e)
  {
            if (this.columnSeparator.ActualWidth!=0&&this.columnSeparator.ActualWidth != this.columnSeparator.MinWidth)
            {
                this.IsLoaded = true;
                SetWidth();
            }
  }

 private void SetWidth()
        {
            if (IsWidthSet)
                return;
            if (!this.IsLoaded)
                return;
            var parentPanel = this.Parent as Panel;
            if (parentPanel != null)
            {
                var textFields = parentPanel.Children.Where(p => p is BpTextField).Cast<BpTextField>().ToList();
                double max = this.LabelWidth;
                foreach (var textField in textFields)
                {
                    max = Math.Max(max, textField.LabelWidth);
                    if (!textField.IsLoaded)
                        return;
                }

                foreach (var textField in textFields)
                {
                    textField.LabelWidth = max;
                }

                this.LabelWidth = max;
            }
        }
        public bool IsLoaded { get; set; }
        public bool IsWidthSet { get; set; }

.

0

Source: https://habr.com/ru/post/1760631/


All Articles