Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting the value of a checkbox programmatically in c# (wpf)

Tags:

c#

I'm working on a small wpf project using c#. I have 2 windows. When I go from one window to the next, i need to have some items preselected on the 2nd window. I have a checkbox that I need to set the value based on information that I pull from the registry. On the 1st window, i have a reference to the 2nd window. How can I set the checkbox to checked so that when the other window opens it's already checked?

 private void btnGoToNextWindow_Click(object sender, RoutedEventArgs e)
    {
            Window2 w2 = new Window2();

            //This doesn't work             
            w2.Checked = true;

            w2.Show();
            this.Close();
     }
like image 223
Michael Wilson Avatar asked Sep 24 '10 18:09

Michael Wilson


2 Answers

You can use the IsChecked property.

I hope this helps. Damian

like image 81
Damian Schenkelman Avatar answered Oct 31 '22 12:10

Damian Schenkelman


Using this:

        Window2 w2 = new Window2();

        //This doesn't work             
        w2.Checked = true;

You're setting the Checked property of the window not the control. It should be somehting like this:

        Window2 w2 = new Window2();        
        w2.MyCheckBox.IsChecked = true;
like image 27
brendan Avatar answered Oct 31 '22 10:10

brendan