locked
AddHandler throws Platform::InvalidArgumentException

    Question

  • Hi,

     I have a Grid^ myGrid in  XAML and I am trying to attach an event handler for the PointerPressed by using AddHandler function as seen below:

    myGrid->AddHandler(UIElement::PointerPressedEvent, ref new PointerEventHandler([](Object^ sender, PointerRoutedEventArgs^ e)
    	{
    		e->Handled = true;
    	}), true);

    This will throw Platform::InvalidArgumentException. Could anyone shed some light on this?

    Thanks,

     Stefan

    Tuesday, September 04, 2012 10:44 PM

Answers

  • Hi Stefan,

    I'd recommend upgrading to the RTM versions. From what you describe there may have been a problem with this in the previews.

    --Rob

    • Proposed as answer by Jesse Jiang Wednesday, September 05, 2012 4:29 AM
    • Marked as answer by stepib Wednesday, September 05, 2012 10:11 AM
    Wednesday, September 05, 2012 2:03 AM
    Owner

All replies

  • Hi Stefan,

    Where do you call this? Where exactly do you see the exception? Can you provide exact repro steps? Are you using Windows 8 RTM or a pre-release version?

    I created a new Blank App, added x:Name="myGrid" to the root Grid, and copied your code snipped to MainPage::OnNavigatedTo(). Everything worked as expected: the handler was called when I touched the screen and no exception was thrown.

    --Rob

    Tuesday, September 04, 2012 10:57 PM
    Owner
  • Hi Rob,

     I am using the Release Preview version of windows 8 and VS 2012 RC. Just like you I have created a blank app and added the code in navigatedto(). 

    Stefan

    Tuesday, September 04, 2012 11:11 PM
  • Hi Stefan,

    I'd recommend upgrading to the RTM versions. From what you describe there may have been a problem with this in the previews.

    --Rob

    • Proposed as answer by Jesse Jiang Wednesday, September 05, 2012 4:29 AM
    • Marked as answer by stepib Wednesday, September 05, 2012 10:11 AM
    Wednesday, September 05, 2012 2:03 AM
    Owner