views:

39

answers:

2

I have a Window that is autosized around it's content. For an animation I'd need it's width and height. ActualWidth is always the max width of the window, Width and Height properties say NaN.

A: 

ActualWidth/ActualHeight will give you the actual sizes of the window - given by the layout system, which is based on the actual rendering of the window. These should be the sizes you are looking for. However, there might be a slight delay in the calculation as it is based on rendering, so if they are wrong I guess they aren't calculated yet - and you got a race condition going on.. You can read more about this in links above, where there are some important notes on when the actual sizes are calculated - and hence - why they can be delayed.

Width/Height are requested sizes, and if not set explicitly they will hold their default values, which is Double.NaN.

stiank81
I need the size of the window before it's rendered, the animation is kind of fade in combined with scaling, which needs to be centered.
laci37
A: 

Whenever possible you should use a ScaleTransform instead of changing Height and Width values when animating a size change. Not only can it help with performance, but it also gets around issues like this since instead of setting a specific size value which you may not know, the scale values are specified as percentages.

John Bowen
I need to center the ScaleTransform. I don't change Height and Width, they are only changed by autosizing and scaling
laci37