Problem with WindowShouldClose

rrradorrrado ✭✭Member ✭✭

I'm handling WindowShouldClose event in my application like this
public override void ViewWillAppear() { base.ViewWillAppear(); View.Window.WindowShouldClose += Window_WindowShouldClose; }
It used to work until I've moved to new machine with new installation. I guess it is caused by newer Mono or Xamarin, now it throws exception:
Event registration is overwriting existing delegate. Either just use events or your own delegate: TestApp.WindowController AppKit.NSWindow+_NSWindowDelegate
I don't have any class inheriting from NSWindow. How can I solve this? Thank you.

Best Answer

Answers

  • rrradorrrado ✭✭ Member ✭✭

    thank you, I've set View.Window.Delegate directly and it works

  • IvanIcinIvanIcin ✭✭✭ USMember ✭✭✭

    I understand that this has happened by change that you haven't perceived and thus one can't blame you, but will this be the final solution?

    I think that you need to remove this crashing APIs until you find the solution that works out of the box. It can't be acceptable that developers will ship crashing applications for the code that worked.

    Possibly you can set that Window.WeakDelegate = null during the event subscription?

  • IvanIcinIvanIcin ✭✭✭ USMember ✭✭✭

    Also
    View.Window.WeakDelegate = null
    doesn't work

  • ChrisHamonsChrisHamons Xamurai USForum Administrator, Xamarin Team Xamurai
    edited September 3

    I've filed https://github.com/xamarin/xamarin-macios/issues/6898 for us to look into the specifics of this case. If nulling out the WeakDelegate beforehand does not fix it, please reduce it to a simple test case and attach it.

    In general however, assigning to the Delegate property something implementing the protocol instead of using C# Delegates is a preferred pattern, and one you should use whenever possible.

  • IvanIcinIvanIcin ✭✭✭ USMember ✭✭✭

    Actually I've already submitted it to github https://github.com/xamarin/xamarin-macios/issues/6884 but it was closed due to this thread :D . I thought to comment there that it should be opened...

  • ChrisHamonsChrisHamons Xamurai USForum Administrator, Xamarin Team Xamurai
    edited September 3

    Without a sample (or comment) to show why my advice didn't work, it appeared to be a duplicate at the time.

Sign In or Register to comment.