Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 网格拆分器之间出现不需要的间隙_C#_Wpf_Xaml_Grid_Gridsplitter - Fatal编程技术网

C# 网格拆分器之间出现不需要的间隙

C# 网格拆分器之间出现不需要的间隙,c#,wpf,xaml,grid,gridsplitter,C#,Wpf,Xaml,Grid,Gridsplitter,我希望在不修改其余拆分器的行为的情况下,防止在wpf窗口中出现间隙。请注意,最长的垂直分离器应该能够向左滑动;我只是不想在移动时出现间隙。在GridSplitters中添加了一条注释,以弥补不需要的间隙。如何防止出现间隙?我的XAML代码如下所示: <Window x:Class="MyAdvancedGrid.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

我希望在不修改其余拆分器的行为的情况下,防止在wpf窗口中出现间隙。请注意,最长的垂直分离器应该能够向左滑动;我只是不想在移动时出现间隙。在GridSplitters中添加了一条注释,以弥补不需要的间隙。如何防止出现间隙?我的XAML代码如下所示:

 <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>

这是因为您的水平拆分器仅跨越2列

如果希望水平拆分器跨越所有3列(高垂直拆分器的左侧),则应将其放在第1列中,并使列跨度为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>


忽略这个问题。我找到了答案。替换“水平对齐”“左”“与”水平对齐=“伸展”在中间GridSplitter产生所需的行为。