locked
Difference between registering an event handler in XAML and in C++ file

    Question

  • In a Direct2D+XAML app, some event handler functions are registered in DirectXPage.xaml

        <SwapChainBackgroundPanel x:Name="SwapChainPanel"  PointerMoved="OnPointerMoved" PointerReleased="OnPointerReleased">
    

    I guess we can also register the same event handler functions in C++ file DirectXPage.xaml.cpp

        Window::Current->CoreWindow->PointerReleased +=
            ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &DirectXPage::OnPointerReleased);
    
    So what's the difference between the two methods?
    Friday, October 05, 2012 8:55 AM

Answers

  • There aren't really any difference except what element you are listening to event on. In you XAML case you are listening to Pointer events on SwapChainPanel, and in the other case you are listening to events on the core window / root element. If you wanted to make them the exact same, use SwapChainPanel->PointerReleased instead of CoreWindow.

    • Marked as answer by Leonard Friday, October 05, 2012 2:41 PM
    Friday, October 05, 2012 2:30 PM

All replies

  • There aren't really any difference except what element you are listening to event on. In you XAML case you are listening to Pointer events on SwapChainPanel, and in the other case you are listening to events on the core window / root element. If you wanted to make them the exact same, use SwapChainPanel->PointerReleased instead of CoreWindow.

    • Marked as answer by Leonard Friday, October 05, 2012 2:41 PM
    Friday, October 05, 2012 2:30 PM
  • Thanks.
    Friday, October 05, 2012 2:41 PM