How to negate bool value inside blazor?

Viewed 2216

I'm trying to do this

<MatCheckbox @bind-Value="@(!Checked)" Label="Checkbox"></MatCheckbox>

But it gives me the error

CS0131 The left-hand side of an assignment must be a variable, property or indexer

How can I pass a negated boolean value without creating another property?

I want to bind the value so it's !Checked

1 Answers

As @DavidG said in the comments, you cannot bind a value, you need to bind a property, and !Checked returns a value, not a property.

So the only way to do this is by creating a negated property.

Related