lbugnion / mvvmlight

The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Windows 10 UWP, Windows Presentation Foundation (WPF), Silverlight, Windows Phone.
http://www.mvvmlight.net
MIT License
1.17k stars 310 forks source link

[Android] Command binding throws System.InvalidCastException #38

Open Opachl opened 6 years ago

Opachl commented 6 years ago

Platform: Android Version: GalaSoft.MvvmLight.Platform, Version=5.4.1.0

Pseudo-Code for Bug Description

Query = root.FindViewById<SearchView>(Resource.Id.search); Query.SetCommand<QueryTextSubmitEventArgs>("QueryTextSubmit", ViewModel.TestCMD);

This throws always System.InvalidCastException: Specified cast is not valid.

I also tried other overloads and combinations result is Always the same

MichalPetryk commented 6 years ago

Hi, I can confirm above issue. I face the same problem when i'm trying to set command on EditText's event.

id = FindViewById<EditText>(Resource.Id.edit_id); id.SetCommand("FocusChange", Vm.IdCommand);

Temporary workaround is:

id.FocusChange += (a, b) => { if (Vm.IdCommand.CanExecute(b)) Vm.IdCommand.Execute(b); };

MichaelShapiro commented 5 years ago

isn't this exact situation described in the documentation here?: http://www.mvvmlight.net/doc/xam1.cshtml