title: c# WPF, How to expand form on button click?
body: <p>I'm working on a c# WPF program, and im trying to make the search form expand(grow bigger), when a button is clicked (much like the Expander function, but the entire form). </p>
  
  <p>Picture of the form NOT expanded:
  <a href="https://i.stack.imgur.com/mFZvR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mFZvR.jpg" alt="enter image description here"></a></p>
  
  <p>Picture of the form when expanded:
  <a href="https://i.stack.imgur.com/mgVxy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mgVxy.jpg" alt="enter image description here"></a></p>
  
  <p>I made the controls hidden to begin with, and when the expand button is clicked, the controls is visible, but the form doesnt follow, i have to make the form bigger manually. I tried everything, and I've been searching for hours.</p>
  
  <p>I tried the expander function. I tried the auto sizeToContent function. </p>
  
  <p>Here is the XAML-code:</p>
  
  <pre><code>&lt;Window x:Class="MockUps.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Search" Icon="C:\Users\rasmus\Desktop\Lejos.dk\LejosLogo.jpg" WindowStartupLocation="Manual" Height="319" Width="480"&gt;
  &lt;Grid AllowDrop="False" Height="auto" Width="480" SizeChanged="Grid_SizeChanged" Margin="2,0,1,-151"&gt;
      &lt;ComboBox HorizontalAlignment="Left" Margin="184,24,0,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Electrician"/&gt;
          &lt;ComboBoxItem Content="Metalworker"/&gt;
          &lt;ComboBoxItem Content="Landscaper"/&gt;
          &lt;ComboBoxItem Content="Painter"/&gt;
          &lt;ComboBoxItem Content="Plumber"/&gt;
          &lt;ComboBoxItem Content="Driver"/&gt;
          &lt;ComboBoxItem Content="Craneworker"/&gt;
          &lt;ComboBoxItem Content="Machineworker"/&gt;
      &lt;/ComboBox&gt;
      &lt;Label Content="Job Type" HorizontalAlignment="Left" Margin="47,20,0,0" VerticalAlignment="Top"/&gt;
      &lt;Label Content="Certificate(s)" HorizontalAlignment="Left" Margin="28,60,0,0" VerticalAlignment="Top"/&gt;
      &lt;Label Content="Nationality" HorizontalAlignment="Left" Margin="36,140,0,0" VerticalAlignment="Top"/&gt;
      &lt;Label Content="Language(s)" HorizontalAlignment="Left" Margin="30,100,0,0" VerticalAlignment="Top"/&gt;
      &lt;ComboBox HorizontalAlignment="Left" Margin="184,64,0,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Welding"/&gt;
          &lt;ComboBoxItem Content="Offshore"/&gt;
          &lt;ComboBoxItem Content="Crane C"/&gt;
          &lt;ComboBoxItem Content="Crane B"/&gt;
          &lt;ComboBoxItem Content="Crane A"/&gt;
          &lt;ComboBoxItem Content="Arc-Welding / Lysbuesvejsning"/&gt;
          &lt;ComboBoxItem Content="TIG-Welding"/&gt;
          &lt;ComboBoxItem Content="Gas-Welding"/&gt;
      &lt;/ComboBox&gt;
      &lt;ComboBox HorizontalAlignment="Left" Margin="184,104,0,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Danish"/&gt;
          &lt;ComboBoxItem/&gt;
          &lt;ComboBoxItem Content="Swedish"/&gt;
          &lt;ComboBoxItem Content="Norwegian"/&gt;
          &lt;ComboBoxItem Content="Deutsch"/&gt;
          &lt;ComboBoxItem Content="Polish"/&gt;
          &lt;ComboBoxItem Content="English"/&gt;
      &lt;/ComboBox&gt;
      &lt;ComboBox HorizontalAlignment="Right" Margin="0,104,27,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Danish"/&gt;
          &lt;ComboBoxItem Content="Swedish"/&gt;
          &lt;ComboBoxItem Content="Norwegian"/&gt;
          &lt;ComboBoxItem Content="Deutsch"/&gt;
          &lt;ComboBoxItem Content="Polish"/&gt;
          &lt;ComboBoxItem Content="English"/&gt;
      &lt;/ComboBox&gt;
      &lt;ComboBox HorizontalAlignment="Left" Margin="184,144,0,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Danish"/&gt;
          &lt;ComboBoxItem Content="Swedish"/&gt;
          &lt;ComboBoxItem Content="Norwegian"/&gt;
          &lt;ComboBoxItem Content="German"/&gt;
          &lt;ComboBoxItem Content="Polish"/&gt;
      &lt;/ComboBox&gt;
      &lt;Label Content="Drivers License" HorizontalAlignment="Left" Margin="15,180,0,0" VerticalAlignment="Top"/&gt;
      &lt;ComboBox HorizontalAlignment="Left" Margin="184,180,0,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="B - Car"/&gt;
          &lt;ComboBoxItem Content="C1 - Small Truck"/&gt;
          &lt;ComboBoxItem Content="C - Big Truck"/&gt;
          &lt;ComboBoxItem Content="D1 - Small Bus"/&gt;
          &lt;ComboBoxItem Content="D - Big Bus"/&gt;
          &lt;ComboBoxItem Content="E - Trailer"/&gt;
      &lt;/ComboBox&gt;
      &lt;ComboBox HorizontalAlignment="Right" Margin="0,64,27,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Welding"/&gt;
          &lt;ComboBoxItem Content="Offshore"/&gt;
          &lt;ComboBoxItem Content="Crane C"/&gt;
          &lt;ComboBoxItem Content="Crane B"/&gt;
          &lt;ComboBoxItem Content="Crane A"/&gt;
          &lt;ComboBoxItem Content="Arc-Welding / Lysbuesvejsning"/&gt;
          &lt;ComboBoxItem Content="TIG-Welding"/&gt;
          &lt;ComboBoxItem Content="Gas-Welding"/&gt;
      &lt;/ComboBox&gt;
      &lt;Button Content="Search" HorizontalAlignment="Left" Margin="137,257,0,0" VerticalAlignment="Top" Width="75"/&gt;
      &lt;Label Content="Experience" HorizontalAlignment="Left" Margin="37,220,0,0" VerticalAlignment="Top"/&gt;
      &lt;ComboBox HorizontalAlignment="Left" Margin="184,220,0,0" VerticalAlignment="Top" Width="120"&gt;
          &lt;ComboBoxItem Content="Min. 5 Years"/&gt;
          &lt;ComboBoxItem Content="Min. 10 Years"/&gt;
          &lt;ComboBoxItem Content="Min. 15 Years"/&gt;
          &lt;ComboBoxItem Content="Min. 20 Years"/&gt;
      &lt;/ComboBox&gt;
      &lt;Image HorizontalAlignment="Right" Height="96" VerticalAlignment="Top" Width="120" Margin="0,144,27,0" Source="C:\Users\rasmus\Desktop\Lejos.dk\LejosLogo.jpg" Stretch="Fill"/&gt;
      &lt;Button Content="Expand" HorizontalAlignment="Left" Margin="268,257,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/&gt;
      &lt;Label x:Name="lblGender" Content="Gender" HorizontalAlignment="Left" Margin="55,300,0,0" VerticalAlignment="Top" Visibility="Hidden"/&gt;
      &lt;Label x:Name="lblMinAge" Content="Min. Age" HorizontalAlignment="Left" Margin="47,340,0,0" VerticalAlignment="Top" Visibility="Hidden"/&gt;
      &lt;Label x:Name="lblMaxAge" Content="Max. Age" HorizontalAlignment="Left" Margin="47,380,0,0" VerticalAlignment="Top" Visibility="Hidden"/&gt;
      &lt;ComboBox x:Name="CBGender" HorizontalAlignment="Left" Margin="184,304,0,0" VerticalAlignment="Top" Width="120" Visibility="Hidden"&gt;
          &lt;ComboBoxItem Content="Male"/&gt;
          &lt;ComboBoxItem Content="Female"/&gt;
      &lt;/ComboBox&gt;
      &lt;ComboBox x:Name="CBMinAge" HorizontalAlignment="Left" Margin="184,344,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="CBMinAge_SelectionChanged" Visibility="Hidden"/&gt;
      &lt;ComboBox x:Name="CBMaxAge" HorizontalAlignment="Left" Margin="184,384,0,0" VerticalAlignment="Top" Width="120" Visibility="Hidden"/&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks Guys
  //Rasmus</p>