A.Manikandan
A.Manikandan

Reputation: 19

Wpf Button Width Based On Window Size

I have stackpanel with three buttons.. like below

 <stackpanel orientation="Horizontal">
    <Button Content="btnone" width="100" height="50"/>
    <Button Content="btntwo" width="100" height="50"/>
    <Button Content="btnthree" width="100" height="50"/>
</stackpanel> 

when i change the window size the buttons will be resized to cover entire window width.. Assume that currently my window width is 300.. Kindly help me..

Upvotes: 1

Views: 3824

Answers (1)

B.K.
B.K.

Reputation: 10152

A Grid panel would probably be more appropriate here than a StackPanel. If I understand your question correctly, then this will do what you want:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button Content="One" Grid.Column="0" Height="50" Margin="10"/>
    <Button Content="Two" Grid.Column="1"  Height="50" Margin="10"/>
    <Button Content="Three" Grid.Column="2" Height="50" Margin="10"/>
</Grid>

enter image description here

Upvotes: 3

Related Questions