Take the 2-minute tour ×

What I am trying to do is show a window, that does not explicitly have a height/width, (both values ommited or set to Auto). I was guessing that the window would find out its size by auto - calculating all contained usercontrols sizes, but this doesn't actually work!

Instead I get a big window with Actualwidth and Actualheight values both set to 512 (?!?!)

Window declaration:

<Window x:Class="Window3"

Showing this window as a dialog via:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
    Dim dlg As New Window3
End Sub

Is there a solution for this? I don't want to explicitly set the size of my window because many controls in the form will be collapsed based on constructor parameters, and trying to find the actual size of the form would be tricky (and ugly).

share|improve this question
You may also want to center the window with .WindowStartupLocation set to "CenterScreen" –  Anders Lindén Jul 5 '12 at 14:16
add comment

1 Answer

up vote 168 down vote accepted

Set the window's property SizeToContent to "WidthAndHeight". This should help.

share|improve this answer
add comment

Your Answer


