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.

- 3,741
- 12
- 49
- 72

- 510
- 4
- 17
3 Answers
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.

- 25,418
- 43
- 131
- 202
-
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 Sep 19 '10 at 20:45
You can use the Window's UpdateLayout()-Method to have ActualWidth
and ActualHeight
validated.

- 3,741
- 12
- 49
- 72

- 508
- 3
- 7
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.

- 3,741
- 12
- 49
- 72

- 24,213
- 4
- 58
- 56
-
I need to center the ScaleTransform. I don't change Height and Width, they are only changed by autosizing and scaling – laci37 Sep 20 '10 at 19:34