WPF 垂直网格分割器不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30305207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:08:13  来源:igfitidea点击:

WPF vertical gridsplitter not working

c#wpfgridsplitter

提问by andrea

I have a vertical gridsplitter, but I get an horizontal one instead. here is my XAML

我有一个垂直的网格分割器,但我得到了一个水平的网格分割器。这是我的 XAML

<GroupBox Header="Phase Management">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="5"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="70*"/>
                <RowDefinition Height="30*"/>
            </Grid.RowDefinitions>

            <Button>Test column 0</Button>

            <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FFFFFF" ResizeBehavior="PreviousAndNext"/>

            <Button Grid.Column="2">Test column 2</Button>

        </Grid>
    </GroupBox>

enter image description here

在此处输入图片说明

in the grid I have a stack panel, a data grid and some text boxes. Any idea of why I'm having the wrong behavior?

在网格中,我有一个堆栈面板、一个数据网格和一些文本框。知道为什么我有错误的行为吗?

回答by Ben

Try to add additional properties like

尝试添加其他属性,如

<GridSplitter Grid.Column="1"
              ResizeDirection="Columns"
              ResizeBehavior="PreviousAndNext"
              HorizontalAlignment="Stretch"/>

for the direction (in your case "Columns") and for the behavior (in the example for resizing in both directions, left and right).

用于方向(在您的情况下为“列”)和行为(在示例中用于向左和向右调整大小)。

回答by Bj?rn

Your XAML doesn't work. Please fix it.

您的 XAML 不起作用。请修复它。

Anyway I took some of your code and made some minor changes so it compiled and I get a vertical splitter:

无论如何,我拿走了你的一些代码并做了一些小改动,所以它编译了,我得到了一个垂直拆分器:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="5"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="70*"/>
        <RowDefinition Height="30*"/>
    </Grid.RowDefinitions>

    <Button>Test column 0</Button>

    <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FFFFFF"/>

    <Button Grid.Column="2">Test column 2</Button>
</Grid>