question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Command is missing on Checkbox control

See original GitHub issue

Description

Why does Button have an ICommand to handle the click event but Checkbox has no such convenience?

Steps to Reproduce

Add Checkbox to view/control.

Version with bug

Release Candidate 3 (current)

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

windows 10.0.19041.0

Did you find any workaround?

Community toolkit EventToCommand.

Writing code in the setter of a property bound to IsChecked. The horror.

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sam-wheatcommented, May 23, 2022

The MVVM pattern is a natural choice for .NET MAUI apps

Yes, it is. Please use this ticket or raise others to implement commanding robustly not just for Checkbox but for all controls (ListView.SelectionChanged).

0reactions
Laimcommented, Feb 18, 2023

I just discovered that CommunityToolkit.Mvvm adds auto-generated methods for each of the properties Changed and Changing for any ObservableProperty you create. So if your property is called IsSelected, you can do this:

[ObservableProperty]
private bool _isSelected;

partial void OnIsSelectedChanged(bool value)
{
    //do what you would otherwise do in a Command here
}

Found this info here. This is probably a cleaner-ish workaround? https://learn.microsoft.com/en-us/dotnet/communitytoolkit/mvvm/generators/observableproperty

In my case, this worked for me as a workaround but it’s still a bit annoying we even have to do it! Thank you for commenting it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make checkbox trigger a command when checked?
I have a checkbox and a [RelayCommand] in the viewmodel that I want to link it to so that the command runs when...
Read more >
Missing checkboxes? | MrExcel Message Board
Right click on them and go to the format control. Then click on the Properties tab and select the appropriate radio button to...
Read more >
[Fix] “Users Must Enter a User Name and Password to Use ...
When the user runs “control userpasswords2” or “netplwiz” commands, the checkbox is missing in these programs.
Read more >
Add a check box or option button (Form controls)
To add a check box, click the Developer tab, click Insert, and under Form Controls, click · Click in the cell where you...
Read more >
CheckBox in Command Item Template
CheckBox in Command Item Template ... Hi, I almost have the following working but am missing a little bit of information. ... Works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found