WPF vertical gridsplitter not working
Asked Answered
R

2

13

I have a vertical gridsplitter, but I get an horizontal one instead. here is my 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?

Reticule answered 18/5, 2015 at 13:57 Comment(2)
And this wrong behaviour is what? Sorry, but what exactly is the problem?Croissant
I need a vertical gridsplitter, but I got an horizontal one and I can't change itReticule
C
32

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

Croissant answered 18/5, 2015 at 14:7 Comment(0)
S
3

Your XAML doesn't work. Please fix it.

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>
Skutchan answered 18/5, 2015 at 14:4 Comment(4)
changed my code and still not working... see pictureReticule
It looks like a vertical splitter between the buttons... Can't you drag the "splitter column" to the left/right?Delphine
no only up and down (of course in this case it does nothing at all)Reticule
Adding ResizeDirection="Columns" as Ben suggested doesn't do it either? The code I posted works for me in a new/"blank" project.Delphine

© 2022 - 2024 — McMap. All rights reserved.