Panel.Closed isn't triggered on Rhino 8

Hi all,

cc @curtisw

We have been struggling with behavioral differences on Panels between Rhino7 and Rhino8. We were using Panels.Closed event in Rhino7 to be able to handle different ways of panel closing to unregister properly WebView from WpfElementHost as below.

private void PanelsOnClosed(object? sender, PanelEventArgs e)
  {
    if (e.PanelId == typeof(SpeckleRhinoPanelHost).GUID)
    {
      // This check comes from behavioral difference on closing Rhino Panels.
      // IsPanelVisible returns;
      //  - True, when docked Panel closed from the list on right click on panel tab,
      // whenever it is closed with this way, Rhino.Panels tries to reinit this object and expect the different UIElement, that's why we disconnect Child.
      //  - False, when detached Panel is closed by 'X' close button.
      // whenever it is closed with this way, Rhino.Panels don't create this object, that's why we do not disconnect Child UIElement.
      if (!Panels.IsPanelVisible(typeof(SpeckleRhinoPanelHost).GUID))
      {
        return;
      }

      // Unsubscribe from the event to prevent growing registrations.
      Panels.Closed -= PanelsOnClosed;

      // Disconnect UIElement from WpfElementHost. Otherwise, we can't reinit panel with same DUI3ControlWebView
      if (_webView != null)
      {
        // Since WpfHost inherited from Border, find the parent as border and set null it's Child.
        if (LogicalTreeHelper.GetParent(_webView) is Border border)
        {
          border.Child = null;
        }
      }
    }

But on Rhino8 we are not catching this event whenever we close panel from X button on detached panel mode or Close button when detached.

Is there any new API functions that we need to aware of or it is a bug with Panels?

Best

2 Likes

Hi @curtisw, @dale,

We haven’t managed to fix this one yet, do you have any suggestion to fix/workaround this issue?

Hey @oguzhankoral,

I can test some things but off of the top of my head, Unload should call when the Panel is closed.

Hi @CallumSykes

Hmm, I don’t know which Unload function you are referring :thinking:

I think I need to provide more info

In Rhino 7: When I close the panel, it triggers the Panels.Closed event and I can succesfully unbind the logical component.

rider64_1Gu1cg2sav

In Rhino 8: When I try to open already closed panel, having the below issue because cannot unbind the logical component

rider64_qJKuFCuLPE

I cloned your repo and had a look into it, the WpfElement doesn’t have some events I thought it would have.

I’ve created a ticket for us to look into this as it looks a lot like a regression to me.

3 Likes

Thank you for the follow-up! Looking forward to hear about it

Best