Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin Android mvvmlight setCommand无效强制转换_Xamarin_Xamarin.android_Mvvm Light - Fatal编程技术网

Xamarin Android mvvmlight setCommand无效强制转换

Xamarin Android mvvmlight setCommand无效强制转换,xamarin,xamarin.android,mvvm-light,Xamarin,Xamarin.android,Mvvm Light,我正在使用Xamarin Android和mvvmlight 5.0库。我很高兴我可以在我的应用程序中使用数据绑定。它在一些简单的事件中工作得很好,比如“点击”。然而,当我绑定到一个事件(支持工具栏的NavigationClick事件)时,我遇到了一些奇怪的情况。我得到一个无效的强制转换错误,如下所示: 10-23 04:35:05.790 I/MonoDroid(11948): System.InvalidCastException: Cannot cast from source type

我正在使用Xamarin Android和mvvmlight 5.0库。我很高兴我可以在我的应用程序中使用数据绑定。它在一些简单的事件中工作得很好,比如“点击”。然而,当我绑定到一个事件(支持工具栏的NavigationClick事件)时,我遇到了一些奇怪的情况。我得到一个无效的强制转换错误,如下所示:

10-23 04:35:05.790 I/MonoDroid(11948): System.InvalidCastException: Cannot cast from source type to destination type.
10-23 04:35:05.790 I/MonoDroid(11948): at (wrapper castclass) object.__castclass_with_cache (object,intptr,intptr) <IL 0x0002c, 0x0006f>
10-23 04:35:05.790 I/MonoDroid(11948): at System.Reflection.EventInfo.AddEventFrame<Android.Support.V7.Widget.Toolbar, System.EventHandler`1<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs>> (System.Reflection.EventInfo/AddEvent`2<Android.Support.V7.Widget.Toolbar, System.EventHandler`1<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs>>,object,object) <0x00123>
10-23 04:35:05.790 I/MonoDroid(11948): at System.Reflection.EventInfo.AddEventHandler (object,System.Delegate) [0x00074] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Reflection/EventInfo.cs:110
10-23 04:35:05.790 I/MonoDroid(11948): at GalaSoft.MvvmLight.Helpers.Extensions.SetCommand<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs> (object,string,GalaSoft.MvvmLight.Command.RelayCommand`1<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs>,GalaSoft.MvvmLight.Helpers.Binding) <0x002b4>
10-23 04:35:05.790 I/MonoDroid(11948): at LieferwagenAndroid.MainActivity.OnCreate (Android.OS.Bundle) [0x00051] in C:\Users\echan1\Documents\Visual Studio 2015\Projects\LieferwagenAndroid\LieferwagenAndroid\MainActivity.cs:51
10-23 04:35:05.790 I/MonoDroid(11948): at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00013, 0x0008e>
10-23 04:35:05.790 I/MonoDroid(11948): at (wrapper dynamic-method) object.c16833d5-e3e1-469e-9a3a-e4abfcb667ff (intptr,intptr,intptr) <IL 0x00017, 0x00027>
10-23 04:35:05.794 W/art     (11948): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
10-23 04:35:05.796 D/AndroidRuntime(11948): Shutting down VM
NavigationCommand = new RelayCommand(NavigationClickMethod);

    public void NavigationClickMethod()
    {
        Console.WriteLine("Navigation Clicked......");
    }
在我的ViewModel类中,我声明RealyCommand如下:

10-23 04:35:05.790 I/MonoDroid(11948): System.InvalidCastException: Cannot cast from source type to destination type.
10-23 04:35:05.790 I/MonoDroid(11948): at (wrapper castclass) object.__castclass_with_cache (object,intptr,intptr) <IL 0x0002c, 0x0006f>
10-23 04:35:05.790 I/MonoDroid(11948): at System.Reflection.EventInfo.AddEventFrame<Android.Support.V7.Widget.Toolbar, System.EventHandler`1<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs>> (System.Reflection.EventInfo/AddEvent`2<Android.Support.V7.Widget.Toolbar, System.EventHandler`1<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs>>,object,object) <0x00123>
10-23 04:35:05.790 I/MonoDroid(11948): at System.Reflection.EventInfo.AddEventHandler (object,System.Delegate) [0x00074] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Reflection/EventInfo.cs:110
10-23 04:35:05.790 I/MonoDroid(11948): at GalaSoft.MvvmLight.Helpers.Extensions.SetCommand<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs> (object,string,GalaSoft.MvvmLight.Command.RelayCommand`1<Android.Support.V7.Widget.Toolbar/NavigationClickEventArgs>,GalaSoft.MvvmLight.Helpers.Binding) <0x002b4>
10-23 04:35:05.790 I/MonoDroid(11948): at LieferwagenAndroid.MainActivity.OnCreate (Android.OS.Bundle) [0x00051] in C:\Users\echan1\Documents\Visual Studio 2015\Projects\LieferwagenAndroid\LieferwagenAndroid\MainActivity.cs:51
10-23 04:35:05.790 I/MonoDroid(11948): at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00013, 0x0008e>
10-23 04:35:05.790 I/MonoDroid(11948): at (wrapper dynamic-method) object.c16833d5-e3e1-469e-9a3a-e4abfcb667ff (intptr,intptr,intptr) <IL 0x00017, 0x00027>
10-23 04:35:05.794 W/art     (11948): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
10-23 04:35:05.796 D/AndroidRuntime(11948): Shutting down VM
NavigationCommand = new RelayCommand(NavigationClickMethod);

    public void NavigationClickMethod()
    {
        Console.WriteLine("Navigation Clicked......");
    }

因此,如果缺少一些参数,我如何知道应该传递哪些类型的参数?谢谢。

您确定活动名称吗?“点击”不是“导航点击”吗


编辑:您应该尝试此事件“OnOptionsItemSelected”

这是我在Visual Studio 2015和Xamarin.Android中遇到的一个问题。这对Xamarin来说是个挑战。您需要打开projects.csproj文件,然后添加缺少的项。例如:

<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Runtime" />
<Reference Include="System.Globalization" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Net.Primitives" />

这些是我在我的参考资料中丢失的地方