In the C++/WinRT reflection, the API AddHandler is defined as
UIElement::AddHandler(Windows::UI::Xaml::RoutedEvent const& routedEvent, Windows::foundation::IInspectable const& handler, bool handledEventsToo) const
But the handlers seems to only inherit from IUnknown
. For example, this is the declaration of KeyEventHandler:
struct KeyEventHandler : Windows::foundation::IUnknown
What is the solution for registering an event handler?
It seems like we need to call
box_value(handler)
which will convert it into anIInspectable
. It is not obvious at all, and you cannot find any samples on MSDN.