0

我正在尝试创建一种方法,用于检查我的复选框是否未选中,如果是,它将显示一个消息框,然后运行我的循环,该循环应该将我的所有部门设置为不显示,但是我似乎无法为了让我的代码检测复选框何时未选中,它只需点击第一个 if 语句并且即使未选中复选框并将其设置为 false,也不会进一步。

    private void displayOnWebsite_Checked(object sender, RoutedEventArgs e)
    {
        CheckBox displayOnWebsite = sender as CheckBox;

        if (displayOnWebsite.IsChecked == false)
        {
            var departments = model.Name;
            var departmentChildren = model.Children;
            var messagebox = System.Windows.MessageBox.Show("Do you wish to hide all sub deparments and products.",
                 "List of Box",
                 MessageBoxButton.YesNo);

            if (!session.IsConnected)
                session.Reconnect();

            // Used to hide child departments and products.
            if (messagebox == MessageBoxResult.Yes)
            {
                if (departmentChildren != null)
                {
                    int zeroChildren = 0;

                    if (departmentChildren.Count.Equals(zeroChildren))
                    {
                        foreach (Department children in departmentChildren)
                            children.IsVisibleOnWebsite = false;
                    }
                }
            }
            else
                System.Windows.MessageBox.Show("Nevermind then...");
        }
        else
            System.Windows.MessageBox.Show("nothing happened here");
    }

WPF:

                        <CheckBox IsChecked="{Binding IsVisibleOnWebsite}" Name="displayOnWebsite" Style="{StaticResource Label}" Checked="displayOnWebsite_Checked">Display On Website</CheckBox>
4

1 回答 1

2

使用“Unchecked”事件来处理取消选中。

于 2012-10-04T09:30:27.740 回答