我在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;
}
}