tags:

views:

901

answers:

1

I know that in XAML/WPF, I can set the Window size using the Width and Height properties, but suppose I want to set the window size such that the client area (minus the Windows borders/decorations) will be a certain fixed size, what is the easiest way to do that?

Like, suppose I want the client area of the window to be 640x480, ala this:

    <Window x:Class="SomeProject.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Background="Black">

<Canvas Width="640" Height="480"/>
</Window>

How can I ensure the inital Window size is such that it has a 640x480 client size that fits the child canvas perfectly? I'm only really interested in how to easily set this up for startup time, not so worried about how to deal with resize events and such.

Thanks.

+1  A: 

Add the following attribute to the window

SizeToContent="WidthAndHeight"

Rich
Thanks, that's exactly what I was looking for. Not sure how I missed this in the MSDN docs.
The Properties window is a better resource than the MSDN docs. =]
Rich