artefact said:I am trying to do the same thing, except I can't use the DesiredWidth value -- I need the ActualWidth (as the final width is determined by the layout and is not the same thing as the DesiredSize).
Is there a way to get the final width after layout? It would be nice if there was an OnLayoutComplete callback where I could put all of my initialization code that is dependant on post-layout values.
I'm new to C#, coming from a JScript/Actionscript background.
I think I can find a workaround -- using Dispatcher, or watching for a positive value in ActualWidth from a CompositionTarget Rendering event. But please let me know if there is a better way to do it.
Use myControl.UpdateLayout() to fully update the layout of the control and populate the ActualWidth and ActualHeight properties. As it has been already said, your control must be a part of the visual tree or the method won't work.