views:

502

answers:

1

Hi,

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

But I am finding it difficult to set it perfectly inside a Window element.

The Width and Height property of the Window is including the borders. How can I set the inner width and height of the window? The Client width and height.

Say, my form is 300px wide. If I set the width and height of the Window to 300, then the borders take up anywhere from 5 - 15px and only 285 or so pixels are available for the client area where you can add controls. I want to set this client area's width to 300px.

I tried having a container control like a Grid or StackPanel and set its width to 300px and setting the window's widthto auto. But the window was way too wide.

Hope I am making sense.

How can I do it?

+4  A: 

Your approach of setting an inner panel width and letting the window size itself accordingly is correct. What you probably might have missed is the property SizeToContent of the window. Set SizeToContent="WidthAndHeight" and it will work.

Aviad P.
+1 : It worked! Thanks :)
Senthil