且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF网格中子控件之间的间距

更新时间:2021-10-15 03:28:35

最简单的方法是在各个控件上设置边距.在TextBoxes上设置它应该足够了,因为一旦它们间隔开了,Labels将垂直设置在每行的中心,并且仍然有足够的空间.

Easiest way is to set a margin on the individual controls. Setting it on the TextBoxes should be enough, because once they're spaced out the Labels will set vertically in the center of each row and have plenty of space anyway.

您可以使用一种样式设置一次:

You can set it once using a style:

<Grid Margin="4">
    <Grid.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Margin" Value="0,0,0,4" />
        </Style>
    </Grid.Resources>

    ...
</Grid>

这将为网格内任何TextBox的底部添加4像素的边距.

This will add a 4-pixel margin to the bottom of any TextBox inside your grid.