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.

The command interface for buttons - Command.ChangeCanExecute()

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Spilchukcommented, Mar 9, 2023

Also observing this same issue with near identical, just simpler with a toggle. Is there an expected timeline for this fix?

Toggle

0reactions
Spilchukcommented, Mar 11, 2023

Because of this, I kind of gave up on having 2 buttons enable and disable each other. Instead, I combined them but now while in one of those states, I just strictly stick with enabling and disabling one, not both.

Retry1

Here’s a snippet of (effectively) the code here:

image

So happy this condition works instead! Hope this helps troubleshooting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Xamarin.Forms Command Interface
When the user presses the Button , the Button calls the Execute method in the ICommand object bound to its Command property. That's...
Read more >
Commanding - .NET MAUI
A call to ChangeCanExecute causes the Command class to fire the CanExecuteChanged method. The Button has attached a handler for that event and ......
Read more >
All about Command Interface in Xamarin Form - iFour Technolab
To use the command interface, you can specify a data binding that targets the Command property of Button where the source is a...
Read more >
xamarin.forms - Realtime validation of a button, using fody
You are using a Command with a CanExecute method. ... ChangeCanExecute() when you modify any of the related properties (like Users , Users....
Read more >
How to disable Xamarin.Forms button
This article will guide you how to change the enabled state of SfButton with Command interface, based on the toggle value of switch...
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