Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Calculating window size based on content

I need to fit the window's width and height to its content. I'm aware of existance of SizeToClient property of Window, however, if one chooses WidthAndHeight as the value of SizeToClient, window events are fired in invalid way, such that several components raise an exception during Loaded event: "Hwnd of zero is not valid" (for example GlassWindow's SetAeroGlassTransparency from Windows API CodePack).

Is there a workaround? I may calculate the window size manually, but I do not know, how to retrieve the window's chrome sizes (in other words, the real window's content margin sizes).

Details of WPF bug

Best regards -- Spook.

like image 264
Spook Avatar asked Dec 17 '25 04:12

Spook


1 Answers

You could use SystemParameters to determine the size of the chrome. For example, SystemParameters.CaptionHeight.

like image 116
Kent Boogaart Avatar answered Dec 19 '25 21:12

Kent Boogaart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!