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

Custom EventArgs classes should be derived from System.EventArgs (or System.CancelEventArgs) #250

Closed
ghost opened this issue Jun 9, 2020 · 4 comments
Assignees
Labels
feature request feature request

Comments

@ghost
Copy link

ghost commented Jun 9, 2020

Please change the implementations of all custom EventArgs classes in the Microsoft.Web.WebView2.Core namespace to be subclasses of System.EventArgs (or System.CancelEventArgs where appropriate) as prescribed in Events (C# Programming Guide).

Raising Event types that are not derived from System.EventArgs breaks interoperability with various WPF- and WinForms-related libraries and frameworks such as Microsoft.Xaml.Behaviors.

Examples of requested changes:

  • CoreWebView2SourceChangedEventArgs should be implemented as
    public class CoreWebView2SourceChangedEventArgs : System.EventArgs { ... }

  • CoreWebView2NavigationStartingEventArgs should be implemented as
    public class CoreWebView2NavigationStartingEventArgs : System.CancelEventArgs { ... }

AB#26932796

@pagoe-msft
Copy link

@djoe47441 thanks so much for bringing this up - we will look into this. Could you explain some scenarios where interoperability with WPF/WinForms libraries is broken?

@ghost
Copy link
Author

ghost commented Jun 15, 2020

Sure, no problem.

Several WPF-related frameworks (e.g. Microsoft.Xaml.Behaviors.Wpf, MVVM Light Toolkit) provide adapters between

  • Control Events

and either

in order to decouple the ViewModel implementation of the event handling code from the View components in an MVVM-based architecture (see Sample Code).

Detailed analysis for Microsoft.Xaml.Behaviors.Wpf
When subscribing to an Event, the implementation of Microsoft.Xaml.Behaviors.Wpf's EventTriggerBase contains explicit code to verify the argument types of the targeted Events to be derived from System.EventArgs.

This will cause the EventTriggerBehavior to fail on all Events raised by WebView2 that do not follow the convention for Event signatures in C#.
End detailed analysis

I sincerely hope that I will be excused for not presenting similarly detailed proof for all other relevant MVVM-frameworks, or their WinForms-facing counterparts. Especially since my project depends on MXBW.

Suffice it to say that the WebView component being replaced by WebView2 does observe the convention for Event signatures in C# and consequently works well with Microsoft.Xaml.Behaviors.Wpf.

@ghost
Copy link
Author

ghost commented Jun 15, 2020

BTW: Apologies for citing the wrong *Behaviors-project in my initial post - I did mean to point to Microsoft.Xaml.Behaviors.Wpf in the first place.

@champnic
Copy link
Member

This should now be available in WebView2 SDK 1.0.674-prerelease - our .NET events are derived from System.Event where applicable. If this is still an issue please let us know. Thanks!

@champnic champnic added this to the SDK 1.0.674-prerelease milestone Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request
Projects
None yet
Development

No branches or pull requests

3 participants