........

Assign Tap to Grid

I am trying to add my grid with a tap handler:

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

      

and in InitializeComponent();

I get this:

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()}

      

+3


source to share


2 answers


I have the same problem, what did I do in the XAMl page where the XamlParseException was thrown. I checked all the click events, in one of the Tap event handlers I found that it is not navigating the code behind.

Rest is fine. So I check the code behind and found that there is ambiguity in the .dll reference.

GestureEventsArgs

has an ambiguity in the following links.



System.Windows.Input.GestureEventArgs

and Microsoft.Phone.Controls.GestureEventArgs

Therefore, I replace Microsoft.Phone.Controls.GestureEventArgs

withSystem.Windows.Input.GestureEventArgs

It works fine now. One thing I want to note here is after I installed the DLL Toolkit it happened, otherwise my code worked fine until then. As @haxor already pointed out.

+6


source


What is the signature for your Tap method in the code file? When I have this problem, I do the following:

  • Go to Designer for XAML
  • Find the object in which the Tap action is defined
  • Remove text containing the name of the Tap method
  • Save file
  • Double-click the field for the designer to create a new Tap method
  • Compare the new stub method signature to my old one.
  • If there is a difference, correct it in the original method and remove the new method


In pretty much every case, I've screwed something around the event arguments in the method signature (most recently due to the Toolkit installation).

+1


source







All Articles