编程设置在C#中的复选框的值(WPF) [英] setting the value of a checkbox programmatically in c# (wpf)

查看:609
本文介绍了编程设置在C#中的复选框的值(WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#的小WPF项目。我有2个窗口。当我从一个窗口去下,我需要有预先选定的第二个窗口中的一些项目。我有一个复选框,我需要根据我从注册表中提取信息设置的值。 1号窗口,我要第二个窗口的引用。哪能复选框设置为选中状态,以便在其他窗口打开时,它已经被选中?



 私人无效btnGoToNextWindow_Click(对象发件人, RoutedEventArgs E)
{
窗口2 W2 =新窗口2();

//这不起作用
w2.Checked = TRUE;

w2.Show();
this.Close();
}


解决方案

使用这样的:

 窗口2 W2 =新窗口2(); 

//这不起作用
w2.Checked = TRUE;

您所设置的窗口的Checked属性的而不是控制的。它应该是服用点是这样的:

 窗口2 W2 =新窗口2(); 
w2.MyCheckBox.IsChecked = TRUE;


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();
     }

解决方案

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;

这篇关于编程设置在C#中的复选框的值(WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆