I’m new to C#.
I’m trying to uncheck all checkboxes in my application using this code
foreach (CheckBox control in this.Controls.OfType<CheckBox>()) {
control.Checked = false;
}
But in this line CheckBox control in this.Controls.OfType<CheckBox>(), Controls is underlined in red. When I try to run the program, I get the following error:
Error 1 'FedApp.MainWindow' does not contain a definition for 'Controls' and no extension method 'Controls' accepting a first argument of type 'FedApp.MainWindow' could be found (are you missing a using directive or an assembly reference?)
Note I’m using the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
FedApp is the name of the application. Please how do I fix it. Thanks for any suggestion.
To enum the controls in a WPF window I think you should do something like this