How to hide Label or TextBlock inside a WPF Grid
Asked Answered
S

5

9

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?

Stem answered 27/3, 2009 at 16:12 Comment(1)
UPDATE: Damn, it does work when you run it, it was just the designer that does not display it correctly.Stem
S
1

Never mind, it does work when you run it, it was just the designer that does not display it correctly.

Stem answered 27/3, 2009 at 16:24 Comment(0)
A
15

In Code you can use something like the following:

Label1.Visibility = Visibility.Hidden;
Auria answered 27/6, 2011 at 5:51 Comment(0)
S
9

Try Visibility.Collapsed

<TextBlock Visibility="Collapsed">
Safford answered 27/3, 2009 at 16:17 Comment(0)
G
2

@Laxman Singhare you sure about Visibility.Hidden? It should be

this.TextBlock.Visibility = Visibility.Collapsed; 
Godhead answered 3/2, 2015 at 11:42 Comment(1)
Working solution!Crissycrist
S
1

Never mind, it does work when you run it, it was just the designer that does not display it correctly.

Stem answered 27/3, 2009 at 16:24 Comment(0)
H
-3

You could also set with and height == 0

Hammon answered 27/3, 2009 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.