如何在 WPF 网格中隐藏标签或文本块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/690401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide Label or TextBlock inside a WPF Grid
提问by bendewey
I am trying to hide the TextBlock and Label which are placed inside a grid like so:
我试图隐藏放置在网格内的 TextBlock 和 Label ,如下所示:
<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?
但文字并没有消失。任何想法为什么会这样?
采纳答案by Ilker Baltaci
Never mind, it does work when you run it, it was just the designer that does not display it correctly.
没关系,当你运行它时它确实有效,只是设计者没有正确显示它。
回答by Laxman Singh
In Code you can use something like the following:
在代码中,您可以使用以下内容:
Label1.Visibility = Visibility.Hidden;
回答by bendewey
回答by Ilker Baltaci
@Laxman Singhare you sure about Visibility.Hidden? It should be
@Laxman Singhare 你确定 Visibility.Hidden?它应该是
this.TextBlock.Visibility = Visibility.Collapsed;
回答by Muad'Dib
You could also set with and height == 0
你也可以设置和高度== 0