0

I have a check box in my MainPage.xaml file setup like this:

<CheckBox x:Name="chkVwAll" Color="Black"/>

What I'm looking to do is use its properties (preferably the IsChecked property), in a sub-method I have in the MainPage.xaml.cs file and the code I have for that sub-method so far is this:

public static DataTable GetPasswrds()
{
    DataTable pTbl = new DataTable();

    using (SqlConnection c = new SqlConnection(App.ConnStr))
    {
        string query, tmp;

        query = tmp = "";

        if (chkVwAll.IsChecked == true)
        {
           // Will enter code here
        }
    }

    return pTbl;
}

Before I even rebuild and run, I'm getting an error message that says:

An object reference is required for the non-static field, method, or property 'MainPage.chkVwAll'

Is there a way to fix all of this so It will read it properly and it will gain access to the checkbox and its properties?

that . When I type chkVwAll I get a red underline under that, so I know it can't find it. If this can be fixed through binding, how do I bind it so it can be seen? Or is there an easier way to fix this?

BobG
  • 9
  • 1

1 Answers1

1

Your method is static

public static DataTable GetPasswrds()

therefore it cannot access a property or field that is not static. Why not remove the static from this method definition?

Neil
  • 11,059
  • 3
  • 31
  • 56