繁体   English   中英

为什么我的栏不对齐?

[英]Why don't my columns align like they should?

使用以下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>

为什么我的文本框与我所做的列不对齐? 为何组合框确实与列对齐?

似乎您的文本框中的边距设置有误,导致其位置与网格的列未对齐。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM