The command interface for buttons - Command.ChangeCanExecute()
See original GitHub issueThe 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.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also observing this same issue with near identical, just simpler with a toggle. Is there an expected timeline for this fix?
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.
Here’s a snippet of (effectively) the code here:
So happy this condition works instead! Hope this helps troubleshooting.