开发者

C# WPF auto button spacing

开发者 https://www.devze.com 2023-03-19 17:28 出处:网络
I have a simple StackPanel on a grid and I want buttons within that stack panel to take up all space available (space between them should be the same).

I have a simple StackPanel on a grid and I want buttons within that stack panel to take up all space available (space between them should be the same). In case it's not clear, there's a pic:

C# WPF auto button spacing

        <StackPanel Grid.Row="1" Grid.Column="0" Grid开发者_Go百科.ColumnSpan="2" Margin="10" Orientation="Horizontal">
            <Button MinWidth="115">OK</Button>
            <Button MinWidth="115">Cancel</Button>
            <Button MinWidth="115">Cancel</Button>
        </StackPanel>

Is it possible or do I have to just enter margins manually?

Thanks!


Make your StackPanel into a Grid instead (you'll need to refactor what you currently have slightly), and evenly space out all of the columns (using a width of *), and then set each button's alignment to left/center/right respectively, which will achieve the layout you're looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号