网格不会在Landscape中延伸

时间:2013-02-06 12:14:37

标签: c# .net silverlight windows-phone-7

我在我的页面中有这个网格,我有一个问题,在横向模式下它旋转,文本框和按钮卡在中心而不是拉伸,任何想法如何解决它?

                                           

    <!--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>

2 个答案:

答案 0 :(得分:2)

这是因为你使用了stackpanel,只使用网格而是像这样设置列定义!

     <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>

答案 1 :(得分:0)

首先删除宽度=&#34; 480&#34;来自第一个 StackPanel 的属性。同时删除Width =&#34; 349&#34;来自 TextBox 元素的属性。

这应该允许元素在横向模式下伸展。