RSS

Tag Archives: WPF Difference Visibility.Collapsed Visibility.Hidden

WPF: Difference of Visibility.Collapsed and Visibility.Hidden


In a recent trial to rename a TreeViewItem in WPF, I added a TextBlock as well as a Hidden TextBox in the Header, so that when in a “rename”, I will toggle of the TextBlock and TextBox’s visibility and allows for the editing vs static text.

image

It seems fine, right? And running this project, you will notice that it is not exactly what we want. Although the TextBlock/TextBox is hidden, yet the rectangle region it occupies still shows up.

image image
Visibility.Hidden

But when we change the Visibility.Hidden to Visibility.Collapsed, it works like a charm!

image image
Visibility.Collapsed

To recap, the collapsed is more than hidden, and try to use it in replacement of the hidden attribute if you just entered the WPF from Winform.

Advertisements
 
1 Comment

Posted by on September 16, 2012 in Dotnet/C#

 

Tags: