0

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

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

2 回答 2

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>
于 2013-02-06T13:26:44.583 回答
0

首先从第一个StackPanel中删除 Width="480" 属性。还要从TextBox元素中删除 Width="349" 属性。

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

于 2013-02-06T13:28:46.603 回答