Bug 32335 - Using WebView events generated from WebUIDelegate result in WebView from being unusable
Summary: Using WebView events generated from WebUIDelegate result in WebView from bein...
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: PC Mac OS
: Normal normal
Target Milestone: master
Assignee: Bugzilla
Depends on:
Reported: 2015-07-22 18:05 UTC by Aaron Bockover [MSFT]
Modified: 2016-09-26 21:58 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 32335 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Aaron Bockover [MSFT] 2015-07-22 18:05:15 UTC
By subscribing to an event on WebKit.WebView (such as WebView.UIMouseDidMoveOverElement), the web view will become useless unless some other events (presumably) are also subscribed to and handled.

For example:

    webView.UIMouseDidMoveOverElement += (sender, e) => {
        // never reached, presumably as the rest of the web view is
        // rendered broken now by this event subscription

The web view can now not be interacted with... can't focus, select, etc.

Using the delegate pattern however works as expected:

    class CustomWebUIDelegate : WebUIDelegate
        public override void UIMouseDidMoveOverElement (WebView sender,
            NSDictionary elementInformation, NSEventModifierMask modifierFlags)
            // reached as expected

    webView.UIDelegate = new CustomWebUIDelegate ();

I ran into this while working on the Xamarin Inspector.

It seems the general rule of thumb is to just not use C# events since the generated delegates to provide events are often broken.

I suspect the generated delegates need to be more dynamic and interact with the ObjC runtime directly...

    class WebView {
        event EventHandler _backing_UIMouseDidMoveOverElement;

        void UIMouseDidMoveOverElementHandler (...)
            _backing_UIMouseDidMoveOverElement?.Invoke (...);

        public event EventHandler UIMouseDidMoveOverElement {
            add {
                if (_backing_UIMouseDidMoveOverElement == null)
                    RegisterProtocolMethodWithObjCRuntime (
                _backing_UIMouseDidMoveOverElement += value;

            remove {
                _backing_UIMouseDidMoveOverElement -= value;
                if (_backing_UIMouseDidMoveOverElement == null)
                    UnregisterProtocolMethodWithObjCRuntime (

Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-07-27 05:54:24 UTC
This is how our event support works: we add handlers for all delegate methods (old design decision we can't really change now).

However we might be able to fix this for WebView by doing the bindings manually and overriding respondsToSelector (like we did for ABPeoplePickerNavigationController).