Basic question about EventRegistrationToken for Windows Store apps RRS feed

  • Question

  • What is the correct type for keyUpToken in the following snippet for a Windows Store app?

    keyUpToken = coreWindow->KeyUp += 
    			ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &KeyState::OnKeyUp);

    I'm currently using Windows::Foundation::EventRegistrationToken which seems to work fine (at least in my dev environment), but I was just looking at the documentation and it indicates that I should be using System.Runtime.InteropService.WindowsRuntime.EventRegistrationToken.  (Which I'm not even sure how to get to... should I add mscorlib.dll to my additional dependencies?)

    If so, what is the point of Windows::Foundation::EventRegistrationToken?

    Just a bit confused.  Thanks!

    EDIT:  Or, if somebody can point me at a sample that does this the right way, that'd be really helpful!

    • Edited by Mike Muir Wednesday, December 12, 2012 1:42 PM more info
    Wednesday, December 12, 2012 1:37 PM


  • Hi,

    Windows::Foundation::EventRegistrationToken is correct type. This type is used in C++/CX. System.Runtime.InteropService.WindowsRuntime.EventRegistrationToken should be used by .NET developer, like C#/VB.

    As far as I know, this value used for remove the delegate. For example, we want to using new codes in keydown event, we should remove the old one and add the new one.

    In this case, we need coreWindow->KeyUp-= keyUpToken; to remove it.

    Best regards,

    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mike Muir Friday, December 14, 2012 8:34 PM
    Friday, December 14, 2012 3:07 AM