Benjamin Diele
Benjamin Diele

Reputation: 1187

Why don't my columns align like they should?

With the following XAML I get this layout: enter image description here

<GroupBox Header="Adres" Grid.Row="1" Grid.RowSpan="5">
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Label HorizontalAlignment="Left" Content="Straat:"/>
        <TextBox Margin="130,0,0,0" Text="{Binding Address.Street}" Grid.Column="1" Grid.ColumnSpan="3" />

        <Label HorizontalAlignment="Left" Grid.Row="1" Content="Nr:"/>
        <TextBox Margin="130,0,0,0" Text="{Binding Address.Number}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />
        <Label HorizontalAlignment="Left" Grid.Row="1" Content="Ext:" Grid.Column="3"/>
        <TextBox Margin="130,0,0,0" Text="{Binding Address.NumberExtension}" Grid.Row="1" Grid.Column="3" />

        <Label HorizontalAlignment="Left" Content="Gemeente:" Grid.Row="2"/>
        <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.Towns}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch">
        </ComboBox>
        <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}, Path=DataContext.Towns}" Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="2">
        </ComboBox>

        <Label Width="125" HorizontalAlignment="Left" Content="Land:" Grid.Row="3"/>
        <TextBox Margin="130,0,0,0" Text="{Binding Address.Country}" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="3" />
    </Grid>
</GroupBox>

Why don't my textboxes align with the columns I made? And why do the ComboBoxes DO align with the columns?

Upvotes: 1

Views: 39

Answers (1)

learningcs
learningcs

Reputation: 1926

It seems the margins in your textboxes have been mistakenly set, causing their positioning to be misaligned with the grid's columns.

Upvotes: 2

Related Questions