检查c#中复选框的状态(Check the state of a checkbox in c#)

我正在为Windows Phone创建一个应用程序,我需要检查CheckBox的状态这是我的atm;

if (tracking.Checked) { MessageBox.Show("Checked"); }

但if语句中的“Checked”一词用红色下划线标出。 我也试过了

if (tracking != null) { MessageBox.Show("Checked"); }

关于我哪里出错的任何建议/想法? 提前致谢!

I'm creating an app for Windows Phone and I need to check the state of a CheckBox this is what I have atm;

if (tracking.Checked) { MessageBox.Show("Checked"); }

But the word "Checked" in the if statement is underlined in red. I have also tried

if (tracking != null) { MessageBox.Show("Checked"); }

any advice/ideas on where I'm going wrong? Thanks in advance!

最满意答案

您需要使用属性IsChecked

xaml

<CheckBox x:Name="CheckBox" />

cs

if (CheckBox.IsChecked == true) {} else {}

You need to use property IsChecked.

xaml:

<CheckBox x:Name="CheckBox" />

cs:

if (CheckBox.IsChecked == true) {} else {}

更多推荐

Checked,MessageBox,I'm,Show,电脑培训,计算机培训,IT培训"/> <meta name=&q