简体   繁体   English

在WPF中正确填充堆栈面板中的项目

[英]Lining items in a stackpanel correctly in WPF

I am trying to align a textblock, textbox, and button below a gridview. 我正在尝试在gridview下面对齐文本块,文本框和按钮。 Right now they are in the correct order, but they are bunched to the left. 现在他们的顺序是正确的,但他们是在左边。 I want them to be evenly spaced below the gridview from left to right and stretch across the entire window. 我希望它们从左到右均匀地间隔在网格视图下方,并在整个窗口上伸展。 Here is the xaml. 这是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>

Use a grid instead of a stackpanel: 使用网格而不是stackpanel:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM