Inventor, Addins, Modeless WPF Window

If you are building an add in for Inventor and want to setup your window to be modeless and always on top of Inventor itself, like a toolbar, you need to set the Owner property of the window itself and you can use the value stored in the “MainFrameHWND” property of the Inventor application object passed to your addin.

The not so straight forward part is that the Owner property expects a reference to a Window object and all we have is the handle to the Inventor window.

public partial class MyAddinWindow : Window
{
    public MyAddinWindow(int inventorWindowHandle)
    {
        InitializeWindow();

        // setup loaded event
        Loaded += (s, e) =>
        {
            WindowInteropHelper wih = new WindowInteropHandler(this);
            wih.Owner = (IntPtr) inventorWindowHandle;
        };
    }
}