Jonas Rembratt
Jonas Rembratt

Reputation: 1742

How to support element expand/collapse and resize with WPF GridSplitter?

Writing a small WPF app here but I can't crack this problem:

I have a panel at the bottom of a window that the user should expand/collapse at the click of a button. Also, when expanded, the user should be able to resize it by dragging a GridSplitter.

To build this I have laid out the controls in a three-row Grid:

Row[0](Height=*)    = some content (not important for the problem)
Row[1](Height=5)    = GridSplitter (I have also tried setting Row Height to Auto)
Row[2](Height=Auto) = the resizable/expandable/collapsable "panel"

I have tried controlling the height of the "panel". That allows for expanding/contracting but when resizing with the GridSplitter the "panel" doesn't stretch to be resized. I have tried resetting the "panel" Height = double.NaN and it's VerticalAlignment = VerticalAlignment.Stretch when the user starts dragging the splitter but that doesn't work.

If I do not try to control the "panel" Height explicitly it stretches as expected and can be resized by the GridSplitter but that won't allow for Expanding/Contracting at the click of a button.

Any tips on how to achieve both of these features would be great!

Upvotes: 2

Views: 602

Answers (1)

If it's a trigger -- the simplest way -- you can give a RowDefinition a Style, and put the trigger in the Style.Triggers section of the Style.

Upvotes: 1

Related Questions