Skip to content

The command interface for buttons - Command.ChangeCanExecute() #9419

@akhegr

Description

@akhegr

The method call Command.ChangeCanExecute() is explained in the introduced in the guide for buttons in MAUI - link is shown below.
https://docs.microsoft.com/en-us/dotnet/maui/user-interface/controls/button#use-the-command-interface

When you use the code right above the title "Press and release the button".

MultiplyBy2Command = new Command(
                execute: () =>
                {
                    Number *= 2;
                    ((Command)MultiplyBy2Command).ChangeCanExecute();
                    ((Command)DivideBy2Command).ChangeCanExecute();
                },
                canExecute: () => Number < Math.Pow(2, 10));

            DivideBy2Command = new Command(
                execute: () =>
                {
                    Number /= 2;
                    ((Command)MultiplyBy2Command).ChangeCanExecute();
                    ((Command)DivideBy2Command).ChangeCanExecute();
                },
                canExecute: () => Number > Math.Pow(2, -10));

The app is in Windows showing a fine blue button, that changes color from blue to gray, when it reaches the limit.
When you leave the limit again, the button do not change the color, but it is again clickable.

If you reach, the upper limit, and afterwards the lower limit, both buttons are gray, as shown on the picture below.
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions