Question

I have a StackPanel containing a number of UIElements (which have been constructed using a template in from a XAML file) that I wish to display.

To display it in the correctly I need to know its size.

Initially Width/Height/ActualWidth/ActualHeight/DesiredSize are all 0 or NaN. If I call panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)) then its ActualWidth/ActualHeight/DesiredSize are calculated (Width/Height remain as NaN). So far, so good.

However, the ActualWidth / DesiredSize.Width is set to the MinWidth value that was specified in the XAML template, even though, when drawn, the stackpanel is wider than this.

Why does the rendered size not match the ActualWidth/ActualHeight properties?

How can I determine what the rendered size will be so that I can position my panel correctly?

(the panel is for a pop-up tooltip that needs to appear near the mouse pointer, but its position needs adjusting if the tooltip would overflow its allowed area).

Was it helpful?

Solution

You can listen to SizeChanged event of a control to monitor it's size changes. Until a control is rendered, all size properties will be 0/NaN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top