[C] Cast to ICommand instead of Command inside SearchBar
authorJason Smith <jason.smith@xamarin.com>
Thu, 7 Apr 2016 06:09:45 +0000 (23:09 -0700)
committerJason Smith <jason.smith@xamarin.com>
Thu, 7 Apr 2016 06:09:45 +0000 (23:09 -0700)
Xamarin.Forms.Core.UnitTests/SearchBarUnitTests.cs
Xamarin.Forms.Core/SearchBar.cs

index a09aa42..d999382 100644 (file)
@@ -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());
+           }
        }
 }
index 089d942..f3d5161 100644 (file)
@@ -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)
                        {