YosiFZ
YosiFZ

Reputation: 7900

Grid won't stretch in Landscape

I have this grid in my Page and i have a problem that in landscape mode it rotate and the textbox and the button are stuck in the center and not stretch,any idea how to fix it?

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" >
        <StackPanel Orientation="Vertical" Margin="0,0,0,0" Width="480">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
                <TextBox Name="searchTextBox" Height="72" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="10,0,0,0" TextChanged="SearchTextDidChange" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Width="349" HorizontalAlignment="Left"/>
                <Button Content="Search" Margin="0,-3,0,0" VerticalAlignment="Top" Height="77" Click="DidPressSearchButton" HorizontalContentAlignment="Right" VerticalContentAlignment="Top" Padding="14,5,10,6" HorizontalAlignment="Right"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</Grid>

Upvotes: 0

Views: 101

Answers (2)

Mike
Mike

Reputation: 579

First remove the Width="480" attribute from the first StackPanel. Also remove the Width="349" attribute from the TextBox element.

That should allow the elements to stretch on landscape mode.

Upvotes: 0

It is because you use stackpanel, use only the grid instead and set the column definition like this!

     <Grid x:Name="ContentPanel"
          Grid.Row="1"
          Margin="0,0,0,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="130" />
        </Grid.ColumnDefinitions>
                <TextBox Name="searchTextBox"
                         Grid.Column="0"
                         Height="72"
                         TextWrapping="Wrap"
                         Text=""
                         VerticalAlignment="Top"
                         Margin="10,0,0,0"
                         TextChanged="SearchTextDidChange"
                         HorizontalContentAlignment="Left"
                         VerticalContentAlignment="Top"
                          />
                <Button Content="Search"
                        Grid.Column="1"
                        Margin="0,-3,0,0"
                        VerticalAlignment="Top"
                        Height="77"
                        Click="DidPressSearchButton"
                        HorizontalContentAlignment="Right"
                        VerticalContentAlignment="Top"
                        Padding="14,5,10,6"
                        HorizontalAlignment="Right" />
    </Grid>

Upvotes: 2

Related Questions