2010-08-22 96 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>