Search code examples
wpfpopupwindowwindows-ribbon-framework

WPF Microsoft Ribbon popup doesn't collapse


I'm having a ribbon with a menu that opens a popup, like so:

enter image description here

Before I clicked the button that shows the popup like the pic, some logic is triggered (irrelevant how) that changes the active tab in the ribbon. This can occasionally result in the situation that the popup from the previous tab remained visible but a new tab is visible behind it. When I mouseEnter the popup, I get a StackOverFlowException.

I was thinking of "deactivating" the previous tab or so, does anyone know what I'm doing wrong?


Solution

  • I added the following to achieve what I wanted :) This solution is implementation specific (i.e. based on my investigation of the implementation of the ribbon that we use). The implementation needed a different originalSource which I managed to achieve by setting the Source to the RibbonWindow instance.

    private void DismissRibbonPopup()
    {
      // Hack inspired by RibbonHelper; try to close any open RibbonPopups (implicit "from the current ActiveTab").
      UIElement source = Mouse.Captured as UIElement;
      if (source != null)
        source.RaiseEvent(new RibbonDismissPopupEventArgs() { Source = /** I put the RibbonWindow instance here */ });
    }
    

    In my code I call this method and after that I set the new tab to IsSelected = true; This implementation differs slightly from what I came across in the impl. because it had little superfluous code.