开发者

How to calculate a bounding box for an Expander?

开发者 https://www.devze.com 2023-01-05 13:51 出处:网络
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 ca

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:开发者_JAVA技巧//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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消