How can I get C# code to recognize a control from a xaml file in a .NET MAUI application?
20:43 24 Jul 2023

I have a checkbox control in a MainPage.xaml file like this:


and in my MainPage.xaml.cs file, I have a method set up as

public static DataTable GetPasswrds()

Now, the reason I have the method setup as static is because this will run when the program first starts up, and it's located in the MainPage file. This way, I don't have to declare an object first to use it, which would cause an error anyway because of the file that it is in. My problem is that, in this method, I need to get access to the IsChecked property of the checkbox I mentioned earlier. But because I've set up the method as static, it won't recognize it. But if I remove static, yes, it will recognize it, but when the program first runs, I will get a global error because I have to declare MainPage before I use this method, and that would be declaring it more than once.

So how can I get this static method in MainPage.xaml.cs to recognize that checkbox?

Or is there some kind of binding that can be done?

c# xaml maui