5

我正在编写我的第一个 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.Xaml.DLL 中出现 Xamarin.Forms.Xaml.XamlParseException 类型的异常,但未在用户代码中处理。附加信息:在 TapGestureRecognizer 上找不到 BindableProperty CommandProperty”

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

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

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

4

1 回答 1

6

您的代码是有效的,并且应该可以工作,前提是您在最新版本之一上运行它Xamarin.Forms,因为它CommandProperty是全新的。

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

于 2014-07-25T18:53:04.630 回答