posts - 250,  comments - 58,  trackbacks - 5053
  Saturday, September 15, 2007

I pulled a lot of hairs out of my almost bald head today trying to figure this out.  I have a layout to create in WPF which involves a top panel and a bottom panel.  Both the top and bottom panel can expand and collapse.  If I collapse the top panel, the bottom panel should fill the remaining space.  If I collapse the bottom panel, the top panel should fill the remaining space.

The only way I found to set what is going to fill remaining space with the dockpanel is the LastChildFill property.  This is a boolean which determines if the last child should fill the remaining space or not.  This, of course, doesn't work for me.  I want to be able to specify which child will fill.  I need the top to fill when the bottom is collapsed, and the bottom to fill when the top is collapsed.

There may be a better way to do this than my solution, but since I'm constrained with only the last child being able to fill, I had to change the order of the items in the children collection.

dkpRight.Children.Remove(child);

dkpRight.Children.Add(child);

So, when the top collapsed I would remove the bottom and add the bottom thus making it the last child. Likewise, when the bottom collapsed I remove the top and add the top.

Seems like a hack to me, is there a better way?