Search code examples
c#.netweb-applicationsblazormudblazor

Is Mudblazor checked option dead


I have a MudCheckBox that i reference in my code in order to be able to know if i need to check it by default or no.

The thing is that when i use the myCheckBox.Checked = true, i ahve an error telling me that Checked is now obsolete and that i need to use Value.

But when i use my_checkBox.Value, it just tell me that i cant set it outside of the component

I just tried both of the answer but none seems to work

if (_account != null)
{
    _checkAvailable.Checked = ((int)_account.Attributes) % 2 > 0;
    _nullAccount = false;
}

Solution

  • You should be able to do simple parameter binding and default the value to true.

    <MudCheckBox @bind-Value="CheckBox1" />
    
    @code {
        public bool CheckBox1 { get; set; } = true;
    }
    

    Of course instead of setting the property directly like this you'd do it in your method using whatever calculation you require.