tags:

views:

31

answers:

1

What is the correct place to execute code that requires the ActualWidth property.

+1  A: 

Short answer assuming your question relates to the control's lifecycle:

When it is rendered.

As you may have noticed, the Actual(Width|Height) properties are set to zero when accessing them before the control is loaded.

Andreas
yes, but when is the 'when it is shown'? Should I override OnRenderSizeChanged or is there another method where I can be certain that the ActualWidth has been updated?
Patrick Klug
I would slightly correct that to *when it is rendered*, since it doesn't have to be rendered on-screen for the property to be set, but close enough :)
Dan Puzey
Whenever the `Render()` method is called, you can access the `ActualWidth` property.
decyclone
@Patrick: You could use the SizeChanged event handler.@Dan: totally agree, best indicator for this is that it is available in a Loaded event handler.
Andreas
@Andreas: It doesn't seem to be available in the Loaded event handler, at least when I put a control in a tabcontrol it is Loaded before it is displayed and therefore the ActualWidth and ActualHeight are 0. The SizeChanged seems to work. I just wanted to know if there is one 'correct' place where to access ActualWidth and ActualHeight outside of the OnRender method.
Patrick Klug
@Patrick: Then I think that the loaded event is fired completely asynchronously while the control is rendered. I will further examine this because it seems to be a little bit undeterministic to me by now.
Andreas