views:

14

answers:

2

I have an Expander control and i need to calculate its bounds without invisible elements and margins. It commonly can be done by VisualTreeHelper.GetDescendantsBounds. But it seems that the rect is calculated by VisualTreeHelper doesn't depend on the expander state. For example:

http://i.piccy.info/i5/58/39/273958/collapsed.jpg

(i can't post images. sorry)

The same result as for expanded state (light green rectangle on the image). Does anybody know how to solve this problem?

A: 

The Expander control will set its content's visibility to Collapsed, which means it won't be considered during layout and won't be included in GetDescendantBounds. However, the Expander can be forced to have a larger size by the layout engine, and the Expander's own size is included in GetDescendantBounds.

Try setting VerticalAlignment="Top" on the Expander. The default is Stretch, which will allow it to increase in size if the parent has more space available. Also make sure you aren't explicitly setting the Height property.

Quartermeister
Thanks for your answer! But it seems that an expander bounding rectangle doesn't depend on VerticalAlignment (i've tried to change this property to Top). I'll try to make the sample application and attach it to the question.
sedovav
A: 

This is the sample application. The style is applied here to the TreeView control and its items. But the problem doesn't depend on the style.

sedovav