3

我尝试为我的网格添加一个水龙头处理程序:

<Grid x:Name="LayoutRoot" Background="#FF1F1F1F" Tap="OnTap">........</Grid>

InitializeComponent();我得到了这个:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll

Failed to assign to property 'System.Windows.UIElement.Tap'. [Line: 14 Position: 58]

    {System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.UIElement.Tap'. [Line: 14 Position: 58]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at *.NowPlayingPageControl.InitializeComponent()
   at *.NowPlayingPageControl..ctor()}
4

2 回答 2

7

我有同样的问题,我在引发 XamlParseException 的 XAMl 页面中做了什么我检查了所有的点击事件,在一个 Tap 事件处理程序中我发现它没有导航到后面的代码。

休息还可以。所以我检查了后面的代码,发现引用.dll有歧义。

GestureEventsArgs在以下参考文献中存在歧义。

System.Windows.Input.GestureEventArgsMicrosoft.Phone.Controls.GestureEventArgs

所以我替换Microsoft.Phone.Controls.GestureEventArgsSystem.Windows.Input.GestureEventArgs

现在它工作正常。我想在这里指出的一件事是在我安装 Toolkit dll 之后发生了这种情况,否则我的代码在那之前工作正常。正如@haxor 已经指出的那样。

于 2013-07-27T08:00:00.177 回答
1

您的 Tap 方法在代码隐藏文件中的签名是什么?当我遇到这个问题时,我会执行以下操作:

  • 进入 XAML 的设计器
  • 找到定义了 Tap 动作的对象
  • 删除包含 Tap 方法名称的文本
  • 保存文件
  • 双击该字段,以便设计器创建一个新的 Tap 方法
  • 将新存根方法的签名与我的旧方法进行比较
  • 如果有差异,在原来的方法中修复它,并删除新的方法

在几乎所有情况下,我都在方法签名的事件参数部分搞砸了一些东西(最近是因为安装了 Toolkit)。

于 2013-05-01T21:57:04.870 回答