Xamarin.Forms MVVM TapGestureRecognizer

时间:2014-07-25 14:44:43

标签: c# xaml mvvm xamarin.forms

我正在编写我的第一个Xamarin.Forms MVVM应用程序,我正在使用XAML编写视图。我需要能够检测用户何时点击Xamarin.Forms.Label并执行此操作我遵循以下Xamarin指南中的示例:

http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/gestures/#Using_ICommand

我的Label的XAML看起来像这样:

<Label Text="Test Check">
  <Label.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding OnClickCheckOption}"
                          CommandParameter="TestCheck" />
  </Label.GestureRecognizers>
</Label>

当应用程序启动时,这会导致运行时错误:

“Xamarin.Forms.Xaml.XamlParseException类型的异常”出现在Xamarin.Forms.Xaml.DLL中,但未在用户代码中处理。附加信息:在TapGestureRecognizer上找不到BindableProperty CommandProperty“

根据Xamarin API,Xamarin.Forms.TapGestureRecognizer类上没有CommandProperty或CommandParameterProperty的错误显然不正确:

http://iosapi.xamarin.com/?link=T%3aXamarin.Forms.TapGestureRecognizer%2f*

有谁知道我做错了什么?非常感谢任何帮助,提前谢谢!

1 个答案:

答案 0 :(得分:3)

您的代码有效且应该有效,只要您在Xamarin.Forms的最新版本之一上运行它,因为CommandProperty是全新的。

在撰写本文时,您应定位的版本为1.2.2-pre2(nuget pre-release)

相关问题