How can I get the authorized WPF window size?

I have a Window that automatically processes its contents. For animation I need width and height. ActualWidthalways the maximum width of the window, Widthand the Heightproperties say NaN.

+3
source share
3 answers

ActualWidth / ActualHeight will give you the actual window dimensions specified 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 may be a slight delay in the calculation, because it is based on rendering, so if they are wrong, I think they have not been calculated yet - and you have a race condition. You can learn more about this in the links above, where there are some important notes about when the actual sizes are calculated, and therefore why they might be delayed.

Width / Height dimensions are requested, and if they are not specified explicitly, they will adhere to the default values, which are Double.NaN.

+2
source

Window UpdateLayout() - ActualWidth ActualHeight.

+2

If possible, you should use ScaleTransformresizing instead of changing the values Heightand Widthwhen animating. This can help not only in performance, but also around such problems, because instead of setting a value of a certain size, which you may not know, the scale values ​​are set as percentages.

0
source

Source: https://habr.com/ru/post/1765532/


All Articles