Search code examples
outlookvstooutlook-addinoffice-addinsribbonx

VSTO Outlook: Detect when any Outlook backstage view overlaps the explorer or inspector window


Well, every time I need to do things in my Outlook Add-in using VSTO I always get problems, limitations, restrictions, etc.....

Having said that... Now I am trying to detect when explorer or inspector window are not visible as the topmost.

For example, I have a custom task pane which I catch any visibility change through the correspondent VisibleChanged event. This event is triggered when its visibility changes from true to false or vice versa or when the custom task pane is closed for any reason. When the custom task pane is not visible I do some stuff.

The problem I have is the following: If I am in the explorer or inspector window and I click on the Outlook "File" tab/menu, the current view changes and the explorer and inspector are not the topmost (they are not visible) and the worst, the custom task pane VisibleChanged event is triggered.... so in this use case I do not want to do those stuffs when custom task pane is not visible. How can I detect this particular use case? I mean when explorer or inspector window are not displayed as the topmost.


Solution

  • You need to use backstage UI customizations where you could specify callbacks for handling the backstage open and close operations. For example, the following backstage UI XML markup declares the callback for opening the backstage UI:

    <?xml version="1.0" encoding="utf-8"?>
    <!-- customUI is the root tag of all Fluent UI customizations. -->
    <customUI xmlns="https://schemas.microsoft.com/office/2009/07/customui"
              onLoad="OnLoad">
      <!—The Backstage element defines the custom structure of the Backstage UI. -->
      <backstage onShow="OnShow">
    

    So, by getting the onShow callback invoked you will be aware when the task pane is overlapped with a backstage UI in Office applications. See Adding Custom Commands and Changing the Visibility of Controls in the Office 2010 Backstage View for more information.

    The backstage UI is described in depth in the Introduction to the Office 2010 Backstage View for Developers article.

    FYI The Outlook object model provides the Application.ActiveWindow method which returns an object representing the current Microsoft Outlook window on the desktop, either an Explorer or an Inspector object.