Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Disable button when Command can't execute #2067

Closed
njannink opened this issue Mar 19, 2021 · 6 comments
Closed

Enhancement: Disable button when Command can't execute #2067

njannink opened this issue Mar 19, 2021 · 6 comments
Labels
Type: Feature ⚙ Request or idea for a new feature.
Milestone

Comments

@njannink
Copy link
Contributor

When you assign a Command to a Button it would be nice if the Disabled property of the Button would listen to the ICommand.CanExecute(parameter) and the ICommand.CanExecuteChanged event.

@stsrki
Copy link
Collaborator

stsrki commented Mar 19, 2021

Can you explain better? To tell you the truth I'm not that familiar with IComand.

The Disabled is checked before executing the command

protected async Task ClickHandler()
{
    if ( !Disabled )
    {
        await Clicked.InvokeAsync( null );

        if ( Command?.CanExecute( CommandParameter ) ?? false )
        {
            Command.Execute( CommandParameter );
        }
    }
}

@njannink
Copy link
Contributor Author

I will have a look if I can make a PR for this.

Mainly what should happen is that when you set the Command or CommandParameter property of a button that you check the CanExecute method of the ICommand and disable the button when this returns false. Also there is an event ICommand.CanExecuteChanged that you should listen to.

This is also how a Wpf button works.

@David-Moreira
Copy link
Contributor

Hello,
How does this affect normal clicking? On the Web, we do have javascript to consider. Does this affect javascript in any way? I might not want the button to disable automatically and still execute bound javascript?

@njannink
Copy link
Contributor Author

I don't really understand your question, but when you don't assign a command the behavior stays exactly the same as it is now. When you assign a command you will get the expected MVVM behavior as is with Wpf and frameworks like ReactiveUI

@David-Moreira
Copy link
Contributor

Well thanks for the explanation.
It's just me not knowing this feature.

@njannink
Copy link
Contributor Author

@stsrki stsrki added the Type: Feature ⚙ Request or idea for a new feature. label Mar 24, 2021
@stsrki stsrki added this to the 0.9.4 milestone Mar 24, 2021
@stsrki stsrki closed this as completed Mar 24, 2021
@stsrki stsrki moved this to ✔ Done in Development Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature ⚙ Request or idea for a new feature.
Projects
Archived in project
Development

No branches or pull requests

3 participants