帮助我的WPF布局

时间:2010-08-22 08:36:27

标签: wpf telerik

我有一个WPF业务线应用程序。其中大部分都托管在选项卡中的用户控件中。 我有一个问题,找出如何布局这样,它适合任何分辨率(必要时滚动)。 这是代码中描述的问题,因为我真的无法弄清楚如何将其添加到文本中,如果不清楚请告诉我,我会尝试绘制一些内容。

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="*"/>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"></ColumnDefinition> <!--What i actually want to say here isn't "take all remaining space" but "take all remaining space without scrolling, 
                                                    and then scroll based on everything as if this was auto and no longer *-->
    <ColumnDefinition Width="Auto"></ColumnDefinition><!--But what happens for now is that since this is auto , it will not scroll at all untill the * column has fully scrolled-->
  </Grid.ColumnDefinitions>
  <StackPanel>
    <StackPanel Orientation="Horizontal">
      <Label></Label>
      <TextBox></TextBox>
    </StackPanel>
  </StackPanel>
  <StackPanel Grid.Column="1">
    <StackPanel Orientation="Horizontal">
      <button> <!-- I want the button's container to be in an auto column , don't 
               want it to take size away from the fields unless needed but don't
               want it to stay visible at the expense of the fields either -->
    </StackPanel>
  </StackPanel>
  <TelerikGrid:RadGridView Grid.Row="1" Grid.ColumnSpan="2">
    <TelerikGrid:RadGridView.Columns>
      <TelerikGrid:GridViewDataColumn Width="*"/>  <!--  This makes my grid take a bajillon kilometers because it itself is in a Grid's column of * size itself in a scrollviewer -->
    </TelerikGrid:RadGridView.Columns>
  </TelerikGrid:RadGridView>
</Grid>

1 个答案:

答案 0 :(得分:1)

很难说,因为我无法在Window中加载GridView控件。

我建议为Grid中的控件嵌套一个布局管理器Grid,以在控件和GridView之间创建一个分隔。您还应该考虑在一个StackPanel或其他布局管理器中组合所有控件。

无论如何,无论您选择布局管理器还是不需要指定列跨度,此布局都可以让您在控件和GridView之间分离。

<Grid> 
  <Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/>  
    <RowDefinition Height="*"/> 
  </Grid.RowDefinitions> 
  <Grid.ColumnDefinitions> 
    <ColumnDefinition />
  </Grid.ColumnDefinitions> 

  <!-- Place a layout Grid inside your Grid to deal with controls -->
  <Grid Grid.Column="0" Grid.Row="0">
    <Grid.RowDefinitions>
       <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
       <ColumnDefinition />
       <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

    <!-- Removed your nested stack panel -->  
    <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal"> 
      <Label></Label> 
      <TextBox></TextBox> 
    </StackPanel> 
    <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal"> 
      <Button /> 
    </StackPanel> 
  </Grid>

  <!-- Add a spilter bar here  -->

  <!-- No need to span 2 columns anymore...  -->
  <TelerikGrid:RadGridView Grid.Column="0" Grid.Row="1" > 
    <TelerikGrid:RadGridView.Columns> 
      <TelerikGrid:GridViewDataColumn Width="*"/>  
    </TelerikGrid:RadGridView.Columns> 
  </TelerikGrid:RadGridView> 

  <!-- Add a status bar here -->

</Grid>