2013-01-24 69 views
1

我有以下XAML源文件來演示我的工作。如何讓一個控件展開/填充到maxheight,然後展開/填充WPF中的另一個控件?

我希望在垂直調整組的大小時,首先將第一個groupbox展開到最大高度,然後在達到時展開第三個groupbox。第三個groupbox也具有最小高度屬性。

<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="Screen_1_Name" 
    x:Class="TestExpansionScreens.Screen_1" 
    Width="400" Height="400"> 

    <Grid x:Name="LayoutRoot" Background="White" Margin="0,0,0,0"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 

     <GroupBox Header="Thing1" Background="LightGreen" Grid.Row="0" Grid.Column="0" MaxHeight="350"> 
      <Button Content="Stuff1" /> 
     </GroupBox> 

     <GroupBox Header="Thing2" Background="LightBlue" Grid.Row="1" Grid.Column="0"> 
      <TextBox Text="Stuff2" Height="60" /> 
     </GroupBox> 

     <GroupBox Header="Thing3" Background="Pink" Grid.Row="2" Grid.Column="0">   
      <TextBox Text="Stuff3" />   
     </GroupBox> 
    </Grid> 
</UserControl> 

通常,當我只想擴展單個控件來填充可用空間時,我使用DockPanel。我已經用各種各樣的網格和dockpanels構建了這個例子,但是,我一直無法解決如何使它工作。有關如何實現它的任何想法?

感謝

+0

嘗試將高度綁定到轉換器。 http://stackoverflow.com/questions/9083933/gridviewcolumn-width-adjustment/9088071#9088071 – Paparazzi

回答

0

您必須設置MaxHeight你的第一個RowDefinition,而不是在分組框中。該行將長到這個高度,然後所有多餘的空間將被第三行佔據。您還可以將MinHeight添加到第三行。

<Grid x:Name="LayoutRoot" Background="White" Margin="0,0,0,0"> 
     <Grid.RowDefinitions> 
      <RowDefinition MaxHeight="350" /> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition MinHeight="150" /> 
     </Grid.RowDefinitions> 

     <GroupBox Header="Thing1" Background="LightGreen" Grid.Row="0" Grid.Column="0"> 
      <Button Content="Stuff1" /> 
     </GroupBox> 

     <GroupBox Header="Thing2" Background="LightBlue" Grid.Row="1" Grid.Column="0"> 
      <TextBox Text="Stuff2" Height="60" /> 
     </GroupBox> 

     <GroupBox Header="Thing3" Background="Pink" Grid.Row="2" Grid.Column="0"> 
      <TextBox Text="Stuff3" /> 
     </GroupBox> 
    </Grid>