+1  A: 

As I discovered in my question, setting the Height to Double.NaN causes it to reset to SizeToContent happiness. I don't know if it will remember the size of your expander though. You might try Kent's Resizer control to move the sizing behavior to the expander rather than the containing window.

Tom
Yeah...resetting the SizeToContent property has the same basic effect but then you lose expanded state :(. Still working on this.
Paul Alexander
Can someone explain what Tom means? How do you set Height or Width to Double.NaN?
DeveloperDan
In reaction to certain events, you could set Control.Height = Double.Nan;
Tom
A: 

I've found that putting the body of my Window in a View and then putting the view as the sole child in the window solved similar problems...

Not the most desirable solution, but it seems to work.

John Weldon
+3  A: 

You have to make your window non-resizeable if you're going to use SizeToContent. Also, you shouldn't use SizeToContent="Height", and then set an explicit Height. Think about it - which one should WPF believe for the window height, the user's setting or the Content? It can't just switch back and forth between the two.

Paul Betts
Thanks, you saved me a lot of time.
Jonathan Allen
+2  A: 

The easiest way to cope is to take manual resizing out of the equation by setting ResizeMode="NoResize" on the window. However, if you have WindowStyle="None" I've noticed that on Vista Aero this causes the window to completely shed the "chrome" and the window looks awkward. Also, this somewhat of a cop out since it looks like you want to give the user resizing capabilities.

The problem is that you have two conflicting goals: 1.) you always want SizeToContent="Height" when collapsing the expander control, 2.) you want SizeToContent="Height" when expanding the expander control unless the user has manually resized the window (SizeToContent="Manual"), in which case you'd like to return to the user's manual height.

Yikes. I don't think you can get around saving the expanded height yourself. WPF won't remember the user's manual height upon expanding once you've reverted back to SizeToContent="Height" in your collapsed event handler.

Rob Sobers