What are differences between Visibility.Collapsed
and Visibility.Hidden
in WPF?
This question is related to
wpf
wpf-controls
visibility
Visibility : Hidden Vs Collapsed
Consider following code which only shows three Labels
and has second Label
visibility
as Collapsed
:
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
<StackPanel.Resources>
<Style TargetType="Label">
<Setter Property="Height" Value="30" />
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1" />
</Style>
</StackPanel.Resources>
<Label Width="50" Content="First"/>
<Label Width="50" Content="Second" Visibility="Collapsed"/>
<Label Width="50" Content="Third"/>
</StackPanel>
Output Collapsed:
Now change the second Label
visibility
to Hiddden
.
<Label Width="50" Content="Second" Visibility="Hidden"/>
Output Hidden:
As simple as that.
Even though a bit old thread, for those who still looking for the differences:
Aside from layout (space) taken in Hidden and not taken in Collapsed, there is another difference.
If we have custom controls inside this 'Collapsed' main control, the next time we set it to Visible, it will "load" all custom controls. It will not pre-load when window is started.
As for 'Hidden', it will load all custom controls + main control which we set as hidden when the "window" is started.
Source: Stackoverflow.com