wpfresize

WPF shrinking child panel


I'm working on a UI for a WPF application. I have in my window Stack Panel with some Expanders inside. In each Expander are some controls, one being a List Box. What I want to do is have the List Box resize (shrink or grow) when the window is resized. At the moment, when I re-size, the expander are getting clipped off but the listbox (sometimes very long in height) remains unchanged. How do I go about making this happen.

A good example is in Outlook 2007, the "Mail Folder" on the left shrinks with window size but the other controls don't.

Thanks in advance.


Solution

  • I've found something interesting myself. I've extended the grid control with a simple method that fires when the expander is expanded, I would call this.

    RowDefinitions[GetRow(expander)].Height = (expander != selectedExpander) ?
        new GridLength(1, GridUnitType.Auto) :
        new GridLength(1, GridUnitType.Star);
    

    This worked very nicely.