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

后端 未结 3 1514
迷失自我
迷失自我 2021-02-14 01:41

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 check

3条回答
  •  无人共我
    2021-02-14 02:04

    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;
    

提交回复
热议问题