views:

2255

answers:

1

What are differences between Visibility.Collapsed and Visibility.Hidden in WPF?

+24  A: 

The difference is that Visibility.Hidden hides the control, but reserves the space it occupies in the layout. So it renders whitespace instead of the control. Visibilty.Collapsed does not render the control and does not reserve the whitespace. The space the control would take is 'collapsed', hence the name.

The exact text from the MSDN:

Visible: Display the element.
Hidden: Do not display the element, but reserve space for the element in layout.
Collapsed: Do not display the element, and do not reserve space for it in layout.

See: http://msdn.microsoft.com/en-us/library/system.windows.visibility.aspx

Razzie
I couldn't have said it better.
Natrium
That means the width and height of control will set to zero if it was in collapsed.
Sauron
Well, in terms of layout, yes. It does of course more than setting width and height to zero. When Visibility is collapsed, the control can't have focus, you can't navigate to the control using the TAB key, etcetera, all of which still can if it would have a height and width of zero. But again, in terms of layout, you could say that.
Razzie