2011-01-28 44 views
6

我已經在下面的XAML中顯示了我想要做的事情。這很簡單。WPF TextBox Stretching

我有一個包含網格的窗口。該網格包含一個包含多個選項卡項的選項卡控件。代碼中下面顯示的選項卡項目包含一個網格。網格有兩列六行。每行包含一個標籤(第0列)和文本框(第1列)。我希望標籤列能夠根據需要消耗盡可能多的空間。我希望文本框列消耗行的其餘部分。而且,當用戶水平調整窗口大小時,我希望文本框列與窗口收縮並展開。下面的代碼不會這樣做,我不知道我需要做什麼來解決這個問題。

<Grid Background="#18AFA117"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <Button Content="Generate" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="54,8,0,0" Name="Generatebutton" VerticalAlignment="Top" Width="75" Click="Generatebutton_Click" /> 
     <Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="151,8,0,0" Name="CancelButton" VerticalAlignment="Top" Width="75" Grid.Row="1" Click="CancelButton_Click" /> 
     <TabControl HorizontalAlignment="Stretch" Margin="5,5,5,416" Name="tabControl1" VerticalAlignment="Stretch" Height="Auto" SelectionChanged="tabControl1_SelectionChanged"> 
      <TabItem Header="TFS Configuration" Name="TFSTab"> 
       <Grid HorizontalAlignment="Stretch"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto" /> 
         <ColumnDefinition Width="Auto" /> 
        </Grid.ColumnDefinitions> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
        <Label Content="TFS Server:" Grid.Column="0" Grid.Row="0" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label04" VerticalAlignment="Top" /> 
        <Label Content="TFS Workspace Name:" Grid.Column="0" Grid.Row="1" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label05" VerticalAlignment="Top" /> 
        <Label Content="TFS Local Folder:" Grid.Column="0" Grid.Row="2" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label06" VerticalAlignment="Top" /> 
        <Label Content="TFS Framework Solution Path:" Grid.Column="0" Grid.Row="3" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label07" VerticalAlignment="Top" /> 
        <Label Content="TFS Checkin Comments:" Grid.Column="0" Grid.Row="4" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label08" VerticalAlignment="Top" /> 
        <Label Content="TFS Shelveset Name:" Grid.Column="0" Grid.Row="5" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label09" VerticalAlignment="Top" /> 

        <TextBox Grid.Row="0" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSServer" VerticalAlignment="Top"/> 
        <TextBox Grid.Row="1" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSWorkspaceName" VerticalAlignment="Top" /> 
        <TextBox Grid.Row="2" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSLocalFolder" VerticalAlignment="Top" /> 
        <ComboBox Grid.Row="3" Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSSolutionPaths" VerticalAlignment="Top" /> 
        <TextBox Grid.Row="4" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSCheckinComments" VerticalAlignment="Top" /> 
        <TextBox Grid.Row="5" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSShelvesetName" VerticalAlignment="Top" /> 
       </Grid> 
      </TabItem> 

回答

11

設置包含文本框,以「明星」列的寬度:* 無需設置文本框Horizo​​ntalAlignment以伸展;網格負責這一點。

+0

工作就像一個魅力!謝謝。 – 2011-01-28 13:47:55