Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

94
Vistas
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?

9 months ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

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)
{

}
9 months ago · Santiago Trujillo Denunciar

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

9 months ago · Santiago Trujillo Denunciar

0

Multiple answers already but here is another alternative

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

From MSDN

9 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos