【问题标题】:How center several buttons in groupBox如何在 groupBox 中居中几个按钮
【发布时间】:2013-08-16 08:50:48
【问题描述】:

我需要一种方法使 WPF(C#) 中的组框中的几个按钮居中(垂直和/或水平)。

我使用了 stackPanel,但我的按钮粘在一起 :(

【问题讨论】:

    标签: wpf xaml button alignment


    【解决方案1】:

    您可以将所有按钮包装在网格或堆栈面板中,并像这样设置对齐属性..

      <Grid>
    
            <GroupBox Margin="10,10,10,10" FontSize="16" FontWeight="Bold" VerticalAlignment="Stretch"
                  Background="LightGray">
                <GroupBox.Header>
                    Mindcracker Network
                </GroupBox.Header>
            <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
                <Button Content="hello1" Width="100" Margin="5" />
                <Button Content="hello2" Width="100" Margin="5" />
                <Button Content="hello3" Width="100" Margin="5" />
                <Button Content="hello4" Width="100" Margin="5" />
            </StackPanel>
    
    
        </GroupBox>
    
    
    </Grid>
    

    【讨论】:

    • 你的答案是正确的,但我的按钮粘在一起......我该如何解决?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 2014-03-14
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多