【问题标题】:Help with my WPF Layout帮助我的 WPF 布局
【发布时间】:2010-08-22 08:36:26
【问题描述】:

我有一个 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>

【问题讨论】:

  • 行和列从 0 开始编号,而不是 1。你错了。
  • 对不起是一个错字,因为我想做一个更简单的例子,并在可选的地方添加了一些数据(因为如果不添加,它默认为 0/0)。将解决它,但不是导致问题的原因。
  • 是您在 ScrollViewer 中的第一个 StackPanel 吗?否则我认为它根本不会滚动。

标签: wpf telerik


【解决方案1】:

很难说我无法在窗口中加载您的 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> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-25
    • 2011-08-03
    • 2011-08-15
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 2011-07-15
    • 2019-01-25
    相关资源
    最近更新 更多