1

我正在尝试对齐网格视图下方的文本块、文本框和按钮。现在它们的顺序是正确的,但它们被集中在左边。我希望它们从左到右均匀分布在网格视图下方,并延伸到整个窗口。这是xaml。

 <Grid>        
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto"/>                                     
        </Grid.RowDefinitions>
        <StackPanel>          
           <telerik:RadGridView x:Name="radGridView" 
                             GroupRenderMode="Flat"
                             ShowGroupPanel="True"                                                      
                             ColumnWidth="*" 
                             IsReadOnly="True"                                                                                     
                             Grid.Row="0"                                                         
                             CanUserFreezeColumns="False"
                             RowIndicatorVisibility="Collapsed"
                             CanUserResizeColumns="True"
                             ShowGroupFooters="True"                              
                             ShowColumnFooters="True" 
                             ItemsSource="{Binding Path=Tester}" />
            <telerik:RadDataPager x:Name="radDataPager"
                              Grid.Row="1"                                                           
                              PageSize="10"
                              Source="{Binding Items, ElementName=radGridView}"
                              DisplayMode="All"
                              IsTotalItemCountFixed="True"/> 
           <StackPanel Orientation="Horizontal">                           
            <TextBlock Grid.Row="2" 
                       TextWrapping="Wrap"
                       HorizontalAlignment="Stretch"
                       Text="Search Testing"/>
            <TextBox ToolTip="Enter Search into box"
                    x:Name="txtName" 
                    Grid.Row="2"                    
                    FontFamily="Courier New"
                    HorizontalAlignment="Stretch"
                    TextWrapping="Wrap" 
                    Text="{Binding SearchText}"/>
            <telerik:RadButton ToolTip="Click To Search"
                    x:Name="btnSearch"           
                    Content="Search"
                    Grid.Row="2"  
                    HorizontalAlignment="Stretch"           
                    Click="RadButton_Click_1"/>
            </StackPanel>
        </StackPanel>
    </Grid>
4

1 回答 1

3

使用网格而不是堆栈面板:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <TextBlock TextWrapping="Wrap"
               Width="auto"
               HorizontalAlignment="Stretch"
               Text="Search Testing"/>
    <TextBox ToolTip="Enter Search into box"
             Grid.Column="1"
             Width="auto"
             x:Name="txtName"               
             FontFamily="Courier New"
             HorizontalAlignment="Stretch"
             TextWrapping="Wrap" 
             Text="{Binding SearchText}"/>
    <telerik:RadButton ToolTip="Click To Search"
               Grid.Column="2"
               Width="auto"
               x:Name="btnSearch"           
               Content="Search" 
               HorizontalAlignment="Stretch"           
               Click="RadButton_Click_1"/>
</Grid>
于 2013-03-18T19:32:55.400 回答