tags:

views:

406

answers:

1

Hi All

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 doesnt actually work!

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

Window declaration:

<Window x:Class="Window3"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window3" 
  Height="Auto">
<StackPanel>
    <Label>Window</Label>
</StackPanel>
</Window>

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
    dlg.ShowDialog()
End Sub

Has anybody got a solution for this? I dont 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 a tricky... (and ugly)

+13  A: 

try SizeToContent="WidthAndHeight" property on the Window this should help

Muad'Dib
Oh man, thanks for this! This was driving me nuts!
rossisdead
Thanks, that helped me too!
Richard Walters