From: Jason Smith Date: Thu, 7 Apr 2016 06:09:45 +0000 (-0700) Subject: [C] Cast to ICommand instead of Command inside SearchBar X-Git-Tag: beta-2.3.0-pre1~74 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1363f383b17d68fbafadc773b9f06f477f9744c9;p=platform%2Fupstream%2Fxamarin-forms.git [C] Cast to ICommand instead of Command inside SearchBar --- diff --git a/Xamarin.Forms.Core.UnitTests/SearchBarUnitTests.cs b/Xamarin.Forms.Core.UnitTests/SearchBarUnitTests.cs index a09aa42..d999382 100644 --- a/Xamarin.Forms.Core.UnitTests/SearchBarUnitTests.cs +++ b/Xamarin.Forms.Core.UnitTests/SearchBarUnitTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; - +using System.Windows.Input; using NUnit.Framework; namespace Xamarin.Forms.Core.UnitTests @@ -108,5 +108,26 @@ namespace Xamarin.Forms.Core.UnitTests Assert.True (searchBar.IsEnabled); } + + class MyCommand : ICommand + { + public bool CanExecute(object parameter) + { + return true; + } + + public void Execute(object parameter) + { + } + + public event EventHandler CanExecuteChanged; + } + + [Test] + public void DoesNotCrashWithNonCommandICommand() + { + var searchBar = new SearchBar(); + Assert.DoesNotThrow(() => searchBar.SearchCommand = new MyCommand()); + } } } diff --git a/Xamarin.Forms.Core/SearchBar.cs b/Xamarin.Forms.Core/SearchBar.cs index 089d942..f3d5161 100644 --- a/Xamarin.Forms.Core/SearchBar.cs +++ b/Xamarin.Forms.Core/SearchBar.cs @@ -134,8 +134,8 @@ namespace Xamarin.Forms static void OnCommandChanged(BindableObject bindable, object oldValue, object newValue) { var self = (SearchBar)bindable; - var newCommand = (Command)newValue; - var oldCommand = (Command)oldValue; + var newCommand = (ICommand)newValue; + var oldCommand = (ICommand)oldValue; if (oldCommand != null) {