Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
WPF Checkbox check IsChecked

I'm not talking about an event handler for this, but rather a simple If Statement checking if the CheckBox has been checked. So far I have:

if (chkRevLoop.IsChecked == true){}

But that raises the error:

Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)

Is there a way to do this that I'm missing?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can use null coalescing operator. This operator returns right-hand operand if the left-hand operand is null. So you can return false when the CheckBox is in indeterminate state (when the value of IsChecked property is set to null):

if (chkRevLoop.IsChecked ?? false)
{

}
over 4 years ago · Santiago Trujillo Report

0

You have to do this conversion from bool? to bool, to make it work:

if((bool)(chkRevLoop.IsChecked)){}

Since it is already a bool condition you need not to put true false because if it is true then only it will come inside this if condition else not. so, no need to even put chkRevLoop.IsChecked == true here, you are by default asking ==true by puttin IsChecked

over 4 years ago · Santiago Trujillo Report

0

Multiple answers already but here is another alternative

if (chkRevLoop.IsChecked.GetValueOrDefault()) {}

From MSDN

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!