Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stretch button all over the grid, xaml

I have a problem with stretching the button all over the grid.

My code look like this:

<Grid x:Name="LayoutRoot" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="2*"/>
        <RowDefinition Height="8*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <StackPanel Grid.Column="5" Grid.Row="1" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Button Content="Search" Background="#FF13D38D" Click="searchButton_Click" FontSize="48"/>
    </StackPanel>
</Grid>

But it didn't work for me, and stretch the button all over the grid, I tried maxwidth/maxheight but it also didn't work correctly anyone has an idea?

like image 824
MNie Avatar asked Nov 17 '13 14:11

MNie


1 Answers

TL;DR:
Remove the StackPanel (see Charleh's comment below question).

PROBLEM SOLVED

<Grid x:Name="LayoutRoot" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="2*"/>
        <RowDefinition Height="8*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button Content="Search" Background="#FF13D38D" Click="searchButton_Click" FontSize="48" Grid.Column="5" Grid.Row="1"/>
</Grid>
like image 190
MNie Avatar answered Oct 04 '22 02:10

MNie