2014-04-09 26 views
0

我想防止出現在我的wpf窗口中的間隙而不修改剩餘的分離器的行爲。請注意,最長的垂直分離器應該可以向左滑動;我只是不想在移動時出現差距。 GridSplitters添加了一條評論,彌補了不必要的差距。我如何防止差距出現?我的XAML代碼如下:GridSplitters之間出現不需要的間隙

<Window x:Class="MyAdvancedGrid.MainWindow" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      Title="MainWindow" 
      Height="480" 
      Width="600"> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition/> 
       <RowDefinition Height="250"/> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="2*"/> 
       <ColumnDefinition Width="auto"/> 
       <ColumnDefinition Width="*"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <GridSplitter Grid.Row="0" 
          Grid.Column="2" 
          VerticalAlignment="Bottom" 
          HorizontalAlignment="Stretch" 
          Grid.ColumnSpan="2" 
          Background="Black" 
          Height="5" /> <!-- A gap involves this splitter.--> 
      <GridSplitter Grid.Column="1" 
          HorizontalAlignment="Left" 
          Grid.RowSpan="2" 
          Background="Black" 
          VerticalAlignment="Stretch" 
          Width="5"/> <!-- A gap appears between this and the splitter above when this vertical splitter is moved to the left.--> 
      <GridSplitter Grid.Column="2" 
          Grid.Row="1" 
          Grid.ColumnSpan="1" 
          HorizontalAlignment="Right" 
          Grid.RowSpan="1" 
          Background="Black" 
          VerticalAlignment="Stretch" 
          Width="5"/> 
     </Grid> 
    </Window> 
+0

忽視這個問題。我找到了答案。在中間GridSplitter中用「Horizo​​ntalAlignment =」Stretch「」替換「Horizo​​ntalAlignment =」Left「」會產生所需的行爲。 – user2460930

回答

0

它的原因是您的水平分離器只能跨越2列。

如果你想在水平拆分跨越所有3列(左高大的垂直分割的),那麼你就應該把它放在第1列,使ColumnSpan是3

<Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition/> 
      <RowDefinition Height="250"/> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="2*"/> 
      <ColumnDefinition Width="auto"/> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="*"/> 
     </Grid.ColumnDefinitions> 
     <GridSplitter Grid.Row="0" 
         Grid.Column="1" 
         VerticalAlignment="Bottom" 
         HorizontalAlignment="Stretch" 
         Grid.ColumnSpan="3" 
         Background="Black" 
         Height="5" /> <!-- see changes above.--> 
     <GridSplitter Grid.Column="1" 
         HorizontalAlignment="Left" 
         Grid.RowSpan="2" 
         Background="Black" 
         VerticalAlignment="Stretch" 
         Width="5"/> 
     <GridSplitter Grid.Column="2" 
         Grid.Row="1" 
         Grid.ColumnSpan="1" 
         HorizontalAlignment="Right" 
         Grid.RowSpan="1" 
         Background="Black" 
         VerticalAlignment="Stretch" 
         Width="5"/> 
    </Grid> 

enter image description here