rubyraj
rubyraj

Reputation: 611

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?

Upvotes: 5

Views: 3895

Answers (1)

Steve Chadbourne
Steve Chadbourne

Reputation: 6953

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>

Upvotes: 6

Related Questions