[C] Prevent enabling a Button via setting a Command (#308)

This commit is contained in:
Paul DiPietro 2016-09-12 06:51:19 -05:00 коммит произвёл Rui Marinho
Родитель 420ceb37d0
Коммит 368a375f13
3 изменённых файлов: 58 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,56 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 43354, "Button command being set after IsEnabled enables the button", PlatformAffected.All)]
public class Bugzilla43354 : TestContentPage
{
protected override void Init()
{
var buttonIsEnabledSetFirst = new Button
{
Text = "Click to display an alert",
IsEnabled = false,
Command = new Command(() => DisplayAlert("Test", "Message", "Cancel")),
};
var buttonIsEnabledSetSecond = new Button
{
Text = "Click to enable/disable button",
Command = new Command(() =>
{
if (buttonIsEnabledSetFirst.IsEnabled)
buttonIsEnabledSetFirst.IsEnabled = false;
else
buttonIsEnabledSetFirst.IsEnabled = true;
})
};
var buttonSetCommandToNull = new Button
{
Text = "Click to set first button's command to null",
Command = new Command(() => buttonIsEnabledSetFirst.Command = null)
};
Content = Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children =
{
buttonIsEnabledSetFirst,
buttonIsEnabledSetSecond,
buttonSetCommandToNull
}
};
}
}
}

Просмотреть файл

@ -124,6 +124,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42364.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42519.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43354.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />

Просмотреть файл

@ -180,7 +180,7 @@ namespace Xamarin.Forms
void CommandCanExecuteChanged(object sender, EventArgs eventArgs)
{
ICommand cmd = Command;
if (cmd != null)
if (cmd != null && IsEnabled)
IsEnabledCore = cmd.CanExecute(CommandParameter);
}
@ -225,8 +225,6 @@ namespace Xamarin.Forms
Command.CanExecuteChanged += CommandCanExecuteChanged;
CommandCanExecuteChanged(this, EventArgs.Empty);
}
else
IsEnabledCore = true;
}
void OnSourceChanged(object sender, EventArgs eventArgs)