Set the size of the client area of ​​a WPF / XAML window

I have the perfect pixel control layout for the form I want to create. I know the exact width, height and location of each control.

But it's hard for me to set it perfectly inside the Window element.

The Width and Height property of a window includes borders. How to set the inner width and height of a window? Width and height of the client.

Say my shape is 300 pixels wide. If I set the width and height of the window to 300, the borders will be from 5 to 15 pixels, and for the client area, where you can add controls, only 285 pixels are available. I want to set the width of this client area to 300 pixels.

I tried having a container control like Grid or StackPanel and set its width to 300 pixels and set the window width to auto. But the window was too wide.

Hope I make sense.

How can i do this?

+3
source share
1 answer

Your approach to adjusting the internal width of the panel and, accordingly, the correct size of the window. You probably have missed the SizeToContentwindow property . Install SizeToContent="WidthAndHeight"and it will work.

+6
source

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


All Articles