Bug 37975 - Button IsEnabled cannot be Binding
Summary: Button IsEnabled cannot be Binding
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-01-25 05:15 UTC by Jesse Jiang
Modified: 2016-01-27 03:34 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Demo (29.95 KB, application/zip)
2016-01-25 05:15 UTC, Jesse Jiang

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jesse Jiang 2016-01-25 05:15:31 UTC
Created attachment 14706 [details]

I found that the IsEnabled property in Button cannot be put in front of Command, like this
<Button Text="ShouldDisable" TextColor="White" BackgroundColor="Red" IsEnabled="{Binding AllButtonEnable}" Command="{Binding FirstCommand}"/>

It cannot disable the button in this situation. Check the demo in attachment.
Comment 1 Stephane Delcroix 2016-01-25 10:08:19 UTC
The `ICommand` interface, implemented by `Command` has a `bool CanExecute (object)` method, and that is used, in case of a `Button`, to set the `IsEnabled` value.

In your case, you're actually setting `IsEnabled` twice. The first time to `false` with `IsEnabled="{Binding AllButtonEnable}"` and the second time to `true` with `Command="{Binding FirstCommand}"` as your command doesn't use the the `CanExtecute` and thus default to true.

Your command implementation should look more like this

	readonly Command clickCommand = new Command (() => {
		AllButtonEnable = true;
		clickCommand.ChangeCanExecute ();
	}, () => AllButtonEnable);
	public Command SecondCommand { get { return clickCommand; } }

and you don't even need to bind `IsEnabled`
Comment 2 Jesse Jiang 2016-01-27 03:34:44 UTC
Thanks Stephane, It good to learn this.