Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call CheckedChanged from MudCheckBox control

Please help me.

I do not find any CheckedChanged example for MudCheckBox. I got the results related to input control only.

<input type="checkbox" @onchange="HandleCheck" />

I tried the documents but didn't get exact example for MudCheckBox. I'm able to bind successfully to the IsCheckedTrue property. This checkbox is inside the MudTable. All I want to call CheckedChanged event.

<MudCheckBox @bind-Checked="@context.IsCheckedTrue" Color="Color.Secondary" CheckedIcon="@Icons.Material.Filled.RadioButtonChecked" UncheckedIcon="@Icons.Material.Filled.RadioButtonUnchecked"></MudCheckBox>
like image 346
bhoopendra.sahoo Avatar asked Dec 12 '25 11:12

bhoopendra.sahoo


1 Answers

Note that in MudBlazor Version 7 there are a considerable number of breaking changes. One is the parameter name is now Value not Checked. So the bind is to bind-Value. See https://github.com/MudBlazor/MudBlazor/issues/8447

This should work using the new setters and getters.

<MudCheckBox @bind-Checked:get=context.IsCheckedTrue @bind-Checked:set=HandleCheck />

@code {
    private Task HandleCheck(bool value)
    {
        // Set the value in the model
        // Do what you want
        return Task.CompletedTask;
    }
}

Or setting the parameters directly:

<MudCheckBox Checked=context.IsCheckedTrue CheckedChanged=HandleCheck />

@code {
    private Task HandleCheck(bool value)
    {
        // Set the value in the model
        // Do what you want
        return Task.CompletedTask;
    }
}

You should also be able to do this, but there's been compiler problems with this syntax, so it may throw errors:

<MudCheckBox @bind-Checked=context.IsCheckedTrue @bind-Value:after="HandleAfter" />

@code {
    private Task HandleAfter()
    {
        // Do what you want
        return Task.CompletedTask;
    }
}
like image 77
MrC aka Shaun Curtis Avatar answered Dec 15 '25 01:12

MrC aka Shaun Curtis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!