使用以下XAML我得到这个布局:
<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>
为什么我的文本框不与我制作的列对齐?为什么ComboBoxes与列对齐?
答案 0 :(得分:2)
您的文本框中的边距似乎被错误设置,导致其定位与网格列不对齐。