title: System.Windows.Visibility Collapsed vs Hidden
body: <p>I have a control with Visibility set to "Collapsed" and a ToggleButton that changes the visibility between Visibility.Collapsed and Visibility.Hidden.  According to the  <a href="http://msdn.microsoft.com/en-us/library/system.windows.visibility.aspx" rel="nofollow">MSDN Documentation</a> there should be no space allotted for the control within the layout when the control's Visibility is set to "Collaped," but there are no visual differences between the two enumerations. Additionally, the Visibility  of the control is initially set to Collapsed so the initial drawing of the controls should not allot any space for the control. </p>
  
  <p>Is there a concept I am missing, or how do I get an element to take space only when visible?  My end-goal is to have controls appear on conditions based on user-selections that appear north of said display-varied controls, with consistent margins between all controls .   </p>
  
  <p>XAML Snippet:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;StackPanel&gt;
      &lt;TextBox Name="hideTest" DataContext="{StaticResource persistentMemoryBridge}"   Text="HIDETEST" Margin="0,327,31,491" Foreground="Black" Background="Orange" Visibility="Collapsed" /&gt;
      &lt;TextBox DataContext="{StaticResource persistentMemoryBridge}"   Text="{Binding Path=PropertyTest}" Margin="0,386,31,432" Foreground="Black" Background="Yellow"/&gt;
      &lt;ToggleButton Name="tbVisibility" Content="Toggle" Click="ToggleButton_Click" Margin="0,445,65,391"&gt;&lt;/ToggleButton&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>CodeBehind: </p>
  
  <pre class="lang-cs prettyprint-override"><code>private void ToggleButton_Click(object sender, RoutedEventArgs e) {
  
          switch (hideTest.Visibility) {
              case System.Windows.Visibility.Collapsed: {
                  hideTest.Visibility = Visibility.Hidden;
                  tbVisibility.Content = "Hidden";
                  break;    
              }
          case System.Windows.Visibility.Hidden: {
              hideTest.Visibility = Visibility.Visible;
              tbVisibility.Content = "Visible";    
              break;
              }
          case System.Windows.Visibility.Visible: {
              hideTest.Visibility = Visibility.Collapsed;
              tbVisibility.Content = "Collapsed";
              break;
              }
          }
      }
  </code></pre>