microsoft/XamlBehaviorsWpf

Allow EventTrigger to bind to Action events

las-nsc opened this issue · 6 comments

Is your feature request related to a problem? Please describe.
I don't like using full event handlers when I have no need for the sender or eventargs, so I use event Action, but EventTrigger doesn't support these.

Describe the solution you'd like
I feel this is akin to having parameterless methods as event handlers, which IS supported. Potentially an action with arguments might also be desirable, but would require type checking the arguments on the target method to make sure they match the event. I would be happy with just supporting Action with no arguments, but allowing Action<T> (like eventargs without sender, but any type) would be helpful too.

Describe alternatives you've considered
Only alternative is to use full event handlers or write my own trigger that does this.

This is not a change that will be made to the EventTrigger. The EventTrigger is purpose built for events, not actions. If anything this would be a different "ActionTrigger". However, using Actions instead of events is not a common pattern for creating controls in WPF. Especially since you loose the ability to take advantage of the routed event system WPF provides.

At this time, this is not something I think is a good fit for this project.

I wouldn't mind if you wanted to make it a separate trigger (although there will be a lot in common). Routed Events are useful in the View (although I've never personally implemented one, as it's already been done where it's useful) but I would be using this when binding to events in the ViewModel where that's not as relevant.

We would need clear specifications in order to understand the possible scenarios in which this would be used, and how it would benefit the wider developer audience if it were to be considered for implementation. This would include detailed descriptions of the behavior, details of the recommended API, sample code snippets of how it would be used, and various scenarios in which it would be used.

All of that is basically identical to the EventTrigger, except it doesn't give an error when binding to event Action rather than event EventHandler.

Maybe I'm missing something here, but event Action is not a .NET pattern, so I would be quite skeptical of having such an approach on a .NET compliant library.

Having said that, as always, nothing stops you from building and using such a pattern in your own apps!

I don't think of patterns being such rigid rules, more that if the language supports it and it's a better way to do it, that's how I do it. I also have an equivalence in my mind between .NET and C# as it's such an important part of getting anything done, so I want it to support the full range of C# features. I understand what you're saying though, and I guess if it's not the way things are done in official .NET libraries then I'll have to live with that.