Question

When dragging GridSplitters with a mouse - some splitters in my grid work fine, while others jump back to original position before I can drop them at a new position. Sometimes after trying many times and dragging them a little bit and quickly releasing the mouse button helps unblock them, but most often it does not. Sometimes - they just all randomly jump to new positions when dragged.

All this while just clicking on a splitter and using the keyboard - works without any problems.

It seems like it might be related to the number of splitters used - it happens less with fewer splitters.

How to make it work with many columns? My application has dozens of columns in a scrollable grid. I tried capturing mouse input to the splitters, but it did not work.

It seems to be similar problem to another question, but it was never answered and I think I added more details.

<Window
    x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"
    Height="480"
    Width="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />

            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />

            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />
            <ColumnDefinition
                Width="40*" />

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

        <GridSplitter
            Grid.Column="0"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="1"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="2"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="3"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="4"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="5"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="6"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="7"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="8"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="9"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="10"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="11"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="12"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="13"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
        <GridSplitter
            Grid.Column="14"
            Width="6"
            HorizontalAlignment="Right"
            VerticalAlignment="Stretch" />
    </Grid>
</Window>
Was it helpful?

Solution

It looks like a bug with WPF. Same code works perfectly well in Silverlight. Switching to GridSplitters that set HorizontalAlignment="Stretch" and putting them in every other column does not work either. I suppose the best workaround is to roll out my own implementation of a GridSplitter - just a custom control that handles mouse and keyboard events and updates properties of the hosting Grid...

*EDIT

I did roll out my own implementation and it is available on my blog

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top