tags:

views:

1185

answers:

3

I'm using an expander inside a Resizer (a ContentControl with a resize gripper), and it expands/collapses properly when the control initially comes up. Once I resize it, the Expander won't properly collapse, as documented below. I ran Snoop on my application, and I don't see any heights set on Expander or its constituents.

How would I go about convincing Expander to collapse properly again? Or modifying Resizer to not make Expander sad would work as well.

Expander documentation says:

"For an Expander to work correctly, do not specify a Height on the Expander control when the ExpandDirection property is set to Down or Up. Similarly, do not specify a Width on the Expander control when the ExpandDirection property is set to Left or Right. When you set a size on the Expander control in the direction that the expanded content is displayed, the area that is defined by the size parameter is displayed with a border around it. This area displays even when the window is collapsed. To set the size of the expanded window, set size dimensions on the content of the Expander control or the ScrollViewer that encloses the content."

+1  A: 

I resolved the problem by moving the Resizer inside the Expander, but I've run into the Expander issue elsewhere, so would still like an answer if someone has it.

thanks

Tom
A: 

I ran into a similar problem using an Expander inside a Grid with a GridSplitter. The expand /collapse behaviour works fine until I move the splitter... Afterwards, the Expander won't collapse, it only hides its contents.

I'm still looking for a workaround... did you eventually find one ?

A: 

I haven't had a chance to mock up this particular issue since then, but I recently discovered that setting Height or Width to Double.NaN resets it to its default free-spirited behavior.

Ironically, this was from reading the code of the Resizer control I was using in the first place.

Tom
Can someone explain what Tom means? How do you set Height or Width to Double.NaN?
DeveloperDan
This is done in the code-behind. Control.Height = Double.NaN; This will reset your control to allow its container to resize it as desired.
Tom