ListBox Visibility属性无法正常工作

时间:2016-03-02 09:52:29

标签: c# wpf listbox visibility

我在wpf中动态更改Listbox的Visivility属性时遇到问题。单击按钮后,属性更改但我必须双击以刷新它。所以一次点击后,没有任何变化。我怎样才能做到这一点?

<ListBox Visibility="Collapsed" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" Name="listBox" VerticalAlignment="Stretch">
</ListBox>

private void btListBoxAction_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (listBox.Visibility == Visibility.Visible) {
        listBox.Visibility = Visibility.Collapsed;
    }
    else {
        listBox.Visibility = Visibility.Visible;
}

}

0 个答案:

没有答案