Tag Archives: GridSplitter

GridSplitters – Part 3: Limiting the Range of a GridSplitter

Sometimes I look at what people search for when they hit my blog and see some trending questions that don’t seem to have easily findable answers. This one seems to be related to how to set the limit for moving a GridSplitter… Well – you don’t actually touch the GridSplitter to do that. You need to modify your RowDefinition or ColumnDefinition. In a similar way that you can define MinWidth/MaxWidth/MinHeight/MaxHeight on any FrameworkElement – you can do MinWidth/MaxWidth on a ColumnDefinition and MinHeight/MaxHeight on a RowDefinition. By setting these – you limit how much the GridSplitter will be able to resize them. I actually take these into account in my SimpleGridSplitter implementation, so if you have lots of rows or columns in your WPF app – you can use that one. Silverlight works fine there with its own GridSplitter.

Continue reading

Advertisements
Tagged , , , , ,

“Moving GridSplitter with code behind” is not the right question

Occasionally I see people searching for how to move the GridSplitter with code behind…
This is not the right question. You can in theory move the GridSplitter itself with code – it is just a control that is hosted in a Grid (if used correctly), so by adjusting the Margins or ~Alignment properties – you can change its position, but what you really want is to resize the associated column/row – which will also incidentally move the GridSplitter.

Continue reading

Tagged , , , , ,

Fixing WPF GridSplitter

Introduction

While working on a WPF tool for work – I was creating ColumnDefinitions in a Grid dynamically (with code) and also dynamically adding GridSplitters to allow users (myself) to resize the columns. Well, it all worked OK, except for the many times that it did not. I thought I made some mistake when creating these GridSplitters, but it seemed like some other people had similar problems with GridSplitters, namely sometimes – they would not work when used with a mouse. When you drag a splitter – it would spring back to original position and stop being dragged or it would jump to some other random (?) position – maybe resizing one of the columns to 0. I tried to fix it by configuring the GridSplitters in different ways – in code behind, between Begin/EndInit blocks, in XAML – nothing helped. I simplified the repro and it seemed to be happening more often when the Grid had many GridSplitters. I checked the same layout in Silverlight and it worked without any problems (well, except for needing to reference another library since GridSplitters are not available in Silverlight using the basic Visual Studio application template). This seemed to indicate the WPF implementation is just somehow broken and it won’t work. Well then I guess I should implement the control myself – how hard would it be? – handle some mouse and keyboard events and resize an associated ColumnDefinition or RowDefinition…

The Fix – SimpleGridSplitter

Continue reading

Tagged , , , , ,