可能重复:
How can I change listbox item’s visibility property in wp7?
你能帮我用按钮切换列表框的可见性吗?
这就是我所拥有的:
private void button3_Click(object sender, RoutedEventArgs e)
{
listbox1.Visibility = Visibility.Visible;
if (listbox1.Visibility = Visibility.Collapsed) ;
{
Visibility.Visible = true;
}
}
答案 0 :(得分:5)
虽然不像scartag的答案那样简洁,但是SilverLight和WPF现在有了Visibility属性,这就是使用bool设置可见性的日子。
private void button3_Click(object sender, RoutedEventArgs e)
{
if (listbox1.Visibility == Visibility.Collapsed)
{
listbox1.Visibility = Visibility.Visible ;
}
else
listbox1.Visibility = Visibility.Collapsed;
}
答案 1 :(得分:3)
private void button3_Click(object sender, RoutedEventArgs e)
{
listbox1.Visibility = listbox1.Visibility == Visibility.Visible? Visibility.Collapsed : Visibility.Visible;
}