Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align button on stackpanel in windows phone 7?

i have added two buttons in stackpanel and set alignment as shown in the code

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<Button Content="Button" Height="64" Name="button1" Width="160" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Content="Button" Height="64" Name="button2" Width="160" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</StackPanel>

but this doesn't match with my requirement. I want it to be like shown in image below.

enter image description here

So how can i do this?

like image 774
rubyraj Avatar asked Mar 31 '11 06:03

rubyraj


1 Answers

Something like this:

<Grid
    Width="480">

    <Grid.ColumnDefinitions>
        <ColumnDefinition
            Width="*" />
        <ColumnDefinition
            Width="*" />
    </Grid.ColumnDefinitions>

    <Button
        Width="200"
        Content="Clear" />

    <Button
        Grid.Column="1"
        Width="200"
        Content="Options"
        HorizontalAlignment="Right"
        />

</Grid>

UPDATE: Due to popular demand, here is a grid without the fixed width or the columns.

<Grid>

    <Button
        Width="150"
        Content="Clear"
        HorizontalAlignment="Left" 
        />

    <Button
        Width="150"
        Content="Options"
        HorizontalAlignment="Right" 
        />

</Grid>
like image 57
Steve Chadbourne Avatar answered Sep 30 '22 05:09

Steve Chadbourne