WPF: content-based window size calculation

I need to fit the width and height of the window to its contents. I know about the existence of the SizeToClient property for Window, however, if you select WidthAndHeight as the SizeToClient value, window events are fired in an invalid way, so several components throw an exception during the Loaded event: "Hwnd of zero is not valid" (for example, GlassWindow SetAeroGlassTransparency from the Windows API CodePack).

Is there a workaround? I can calculate the window size manually, but I don’t know how to get the window sizes (for example, the sizes of the fields of the real content).

WPF Error Details

Regards - Spook.

+3
source share

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


All Articles