开发者

WPF: find how much space a control needs

In my application I have an area in the main window that at any time can contain one of several different controls.

This controls are generated at runtime and their contents can vary depending on underlying data, so I do not know beforehand how much space they'll take up.

What I want to know is: is there a way to determine at runtime how much space a control needs in order not to be "c开发者_JAVA百科ut off" or need a scroll? ie: how much space does it need to be COMPLETELY visible?

I tried the "DesiredSize" property and it kinda works, but not always: if the control has been used already (it has already a size) it returns it's last used size rather than the correct one, even if I call "InvalidateMeasure()".

Any ideas??


Call Measure on the control. Give it infinite space as the available size for the calculation. Then check the DesiredSize to get the needed width (and/or height).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜