Obviously both prevent the element from being displayed.
Visibility.Hidden
reserves the space that the element will occupy in the layout, so nothing will be redesigned except in this area. Everything is fixed in place, hiding or not. It just hides, but the element is there.
Visibility.Collapsed
does not reserve the space and clean the layout, may require redesign of other elements to adjust positions. It arrow the height and length to zero and the element is no longer there.
If you just change the width
and height
element will change the layout, equal to Collapsed
, but the element remains present, equal to Hidden
, even though invisible, maintaining characteristics of something available, active. For example it can gain focus when the controls are changing elements in navigation, probably with TAB. There could be other consequences. Unless you want to exactly make the element exit the screen, taking away its space, but stay there, it is wrong to use this technique.
Documentation.
Assuming I no longer need to show the element, there would be differences between setting the height and width to zero and using the
Collapsed
?– vinibrsl
@Viníciusbrazil this is complicated to say because it would need to know how the WPF treats the elements, because I don’t know if it would try to render the element even with zero size, I can only imagine in case the element might have focus, even with zero size it is still visible so I imagine that the focus might end up in it yet, which would not happen if I used the
Hidden
orCollapsed
– Leandro Godoy Rosa