2
private void checkBox1_Checked(object sender, RoutedEventArgs e)
{
    if (checkBox1.IsChecked == false)
    {
        grid1.Visibility = System.Windows.Visibility.Hidden;
    }

    if (checkBox1.IsChecked == true)
    {
        grid1.Visibility = Visibility;
    }

}

为什么 grid1.Visibility = System.Windows.Visibility.Hidden;不工作,网格没有隐藏

4

5 回答 5

5

您正在处理该Checked事件,该事件仅在 CheckBox 被选中时发生,而不是在未选中时发生。要解决此问题,请同时处理Unchecked事件

private void checkBox1_Checked(object sender, RoutedEventArgs e) 
{ 
    grid1.Visibility = System.Windows.Visibility.Visible; 
} 

private void checkBox1_Unchecked(object sender, RoutedEventArgs e) 
{ 
    grid1.Visibility = System.Windows.Visibility.Hidden; 
} 
于 2012-08-09T09:53:10.593 回答
2

当复选框不再被选中时,使用Unchecked事件得到通知。

于 2012-08-09T09:53:24.980 回答
0

试试这个,你必须使用折叠

private void checkBox1_Checked(object sender, RoutedEventArgs e)
{
        grid1.Visibility = System.Windows.Visibility.Visible;
}

private void checkBox1_UnChecked(object sender, RoutedEventArgs e)
{

        grid1.Visibility = System.Windows.Visibility.Collapsed;
}
于 2012-08-09T10:04:33.473 回答
0

试试这个代码

protected void checkBox1_Unchecked(object sender, RoutedEventArgs e)
 {
     grid1.Visibility = System.Windows.Visibility.Hidden;
 }

protected void checkBox1_Checked(object sender, RoutedEventArgs e)
  {
     grid1.Visibility = System.Windows.Visibility.Visible; 
  }
于 2012-08-09T10:04:34.240 回答
-1
 private void checkBox1_CheckStateChanged(object sender, RoutedEventArgs e)
    {
        if (checkBox1.Checked)
        {
            grid1.Visibility = System.Windows.Visibility.Hidden;
        }else
        {
            grid1.Visibility = System.Windows.Visibility.Visible;
        }

    }

没有这样的属性 IsChecked。

于 2012-08-09T09:53:23.760 回答