Custom RoutedEventArgs in the managed API
Posted: 05 Apr 2022, 06:31
I'm trying to create a new custom routedevent with my own RoutedEventArgs. Following the WPF idiom, I create a subclass of RoutedEventArgs such as (with application specific fields removed):
When I attempt to use this in a custom RoutedEvent, Noesis complains that:
Implementing InvokeHandler is a challenge; looking at the provided implementations of RoutedEventArgs, the interface assumes that they are P/Invoke wrappers and pass them a IntPtr of the internal native EventArgs. For example,
Is there a way to use Marshal or unsafe, for example, to recover the managed object from the native pointer passed to InvokeHandler? I'm not particularly good at debugging across the managed/native boundary, so am having a bit of a hard time introspecting on the memory at the args pointer to figure out if I can do this myself.
Code: Select all
class ResizeEventArgs : RoutedEventArgs
{
public ResizeEventArgs(RoutedEvent @event, object sender) :
base(@event, sender)
{ }
}
Code: Select all
InvalidOperationException: Event args for ResizeEventHandler have to define the method 'static void InvokeHandler(Delegate handler, IntPtr sender, IntPtr args)'
Code: Select all
internal static new void InvokeHandler(Delegate handler, IntPtr sender, IntPtr args) {
ScrollChangedEventHandler handler_ = (ScrollChangedEventHandler)handler;
if (handler_ != null) {
handler_(Extend.GetProxy(sender, false), new ScrollChangedEventArgs(args, false));
}
}