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

RoutedEventAttribute: How to handle a custom event args type? #62

Open
HavenDV opened this issue Aug 27, 2024 Discussed in #61 · 1 comment
Open

RoutedEventAttribute: How to handle a custom event args type? #62

HavenDV opened this issue Aug 27, 2024 Discussed in #61 · 1 comment
Labels
enhancement New feature or request

Comments

@HavenDV
Copy link
Owner

HavenDV commented Aug 27, 2024

Discussed in #61

Originally posted by fubar-coder August 27, 2024
Hi,

the dependency property source generator stuff really works well. After that, I wanted to try the routed events, but I stumbled over the following problem:

Let's assume that I have an event handler delegate, like EventHandler<MyCustomEventArgs>, with MyCustomEventArgs being defined as:

public class MyCustomEventArgs : RoutedEventArgs
{
  public MyCustomEventArgs(int myValue)
  {
    MyValue = myValue;
  }

  public MyCustomEventArgs(int myValue, RoutedEvent evt)
    : base(evt)
  {
    MyValue = myValue;
  }

  public MyCustomEventArgs(int myValue, RoutedEvent evt, object? source)
    : base(evt, source)
  {
    MyValue = myValue;
  }

  public int MyValue { get; }
}

Now, I'd like to use the following attribute:

[RoutedEvent<EventHandler<MyCustomEventArgs>>("MyCustomEvent", RoutedEventStrategy.Bubble)]

The problem is, that it automatically generates a OnMyCustomEvent, which creates a RoutedEventArgs instead of the needed MyCustomEventArgs.

Is there a way to provide the correct event arguments?

@HavenDV HavenDV added the enhancement New feature or request label Aug 27, 2024
@fubar-coder
Copy link

I'd suggest a simple option, which allows to specify your custom OnMyCustomEvent function name, which has the following effect of suppressing the automatic implementation of the default On* function. This would allow s/o to implement a custom function with the "correct" event arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants