I\'ve got a WPF window with SizeToContent=\"Height\"
. This window contains an
that displays a list of recent activity. What I\'d lik
Try this, it should fit your needs:
<Window ...
SizeToContent="WidthAndHeight"
Height="Auto"
Width="Auto">
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.
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.
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.
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.