Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every RoutedEvent should be usable as Attached Event #9507

Closed
Mrxx99 opened this issue Nov 21, 2022 · 1 comment · Fixed by #15274
Closed

Every RoutedEvent should be usable as Attached Event #9507

Mrxx99 opened this issue Nov 21, 2022 · 1 comment · Fixed by #15274

Comments

@Mrxx99
Copy link
Contributor

Mrxx99 commented Nov 21, 2022

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

@Mrxx99
Copy link
Contributor Author

Mrxx99 commented Nov 21, 2022

I think my proposal would also solve #4009

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants