2010-08-22 85 views
3

我有一个WPF业务线应用程序。它们大部分都在标签页的用户控件中。 我有一个问题,找出如何布局,以便它适合任何解决方案(如有必要滚动)。 这是代码中描述的问题,因为我真的无法弄清楚如何把它放到文本中,如果它不清楚,请让我知道我会尝试绘制一些东西。帮助我的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

行和列的编号从0开始,而不是从1开始。您错了。 – svick 2010-08-22 12:13:21

+0

对不起,我想做一个简单的例子,并添加了一些数据,它是可选的(因为它默认为0/0,如果没有添加)的错字。将解决它,但不是造成问题的原因。 – 2010-08-22 12:59:48

+0

是您的第一个ScrollViewer内的StackPanel吗?否则,我不认为它会滚动。 – 2010-08-22 14:03:51

回答

1

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

我建议在您的网格中为您的控件嵌套一个布局管理器网格,以在您的控件和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>