Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF auto button spacing

Tags:

c#

wpf

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: enter image description here

        <StackPanel Grid.Row="1" Grid.Column="0" Grid.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!


1 Answers

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.

like image 57
qJake Avatar answered Apr 16 '26 05:04

qJake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!