【问题标题】:Xamarin.Forms MVVM TapGestureRecognizerXamarin.Forms MVVM TapGestureRecognizer
【发布时间】:2014-09-17 11:09:01
【问题描述】:

我正在编写我的第一个 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.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*

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

【问题讨论】:

  • 嘿Xamarin 支持点按手势吗?
  • @Arti 你可以在Gestures查看本教程

标签: c# xaml mvvm xamarin.forms


【解决方案1】:

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

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

【讨论】:

  • 是的,没错。我使用的是 Xamarin.Forms v1.0.6186,当我升级到 v1.2.2 时代码开始工作。
猜你喜欢
  • 2021-01-16
  • 2019-11-16
  • 2018-12-10
  • 1970-01-01
  • 2019-02-19
  • 2019-10-10
  • 2022-01-22
  • 2018-06-29
  • 2016-05-06
相关资源
最近更新 更多