Skip to content

Every RoutedEvent should be usable as Attached Event #9507

Closed
@Mrxx99

Description

@Mrxx99

Is your feature request related to a problem? Please describe.
I wanted to use DragDrop events in XAML, like it is commonly done in WPF (e.g. here: Drag-and-Drop Example | Microsoft Docs)

But it does not work because the events on the DragDrop class are no attached events, only standard RoutedEvents.

Describe the solution you'd like
The easiest solution would be to add the missing Add/RemoveHandler methods to DragDrop, but I think it would be better to not require them at all, since they are just wrappers for calling IInteractive.AddHandler, e.g. here:

public static void AddTappedHandler(IInteractive element, EventHandler<RoutedEventArgs> handler)
{
    element.AddHandler(TappedEvent, handler);
}

Instead of requiring these additional methods, why can the Xaml compiler just not directly use element.AddHandler(<Event>, handler)?

This would make it much easier to define attached events, would not lead to head-scratching why this routed event does not work as attached event and would reduce not needed boilerplate code.
Also there is no risk of forgetting to add those methods so the event can be used as attached event, like it was for DragDrop.

Describe alternatives you've considered
Adding the missing (boilerplate) methods to DragDrop and maybe other classes where it yet has to be discovered that they are missing

Additional context
I was wondering for days why the DragDrop events where not working because I was not aware that additional methods would be required, but are missing. That was very frustrating. I know WPF does the same but I see no reason why not improve on it.

Quote from @kekekeks on Telegram:

we can probably automatically call Interactive.AddHandler though

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions