How to hide Label or TextBlock inside a WPF Grid

user65199 picture user65199 · Mar 27, 2009 · Viewed 29k times · Source

I am trying to hide the TextBlock and Label which are placed inside a grid like so:

<TextBlock Grid.Column="3" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Hidden">Text inside TextBlock</TextBlock>
<Label Grid.Column="4" Grid.Row="2" HorizontalAlignment="Center" Visibility="Hidden">Text inside Label</Label>

But the text does not disappear. Any ideas why that is?

Answer

Laxman Singh picture Laxman Singh · Jun 27, 2011

In Code you can use something like the following:

Label1.Visibility = Visibility.Hidden;