1

This is very nearly what I need: How to open a child windows under parent window on menu item click in WPF?

However, my parent object in this case is an Office.Interop.Excel com object while my child object is a System.Windows.Window object. I am wondering if there is a way to get or cast a Window object from the interop.excel object.

The behavior I am looking for is that the window that popups on the excel sheet should be topmost for the excel application only. Setting the property TopMost doesn't work here as the window ends up always being the focus.

Community
  • 1
  • 1
Brandon
  • 89
  • 9
  • 2
    You'll have to use Excel's `Application.Hwnd` property to get the handle to excel's main window. And then use [this Q+A](http://stackoverflow.com/questions/2599053/how-to-set-win32-window-as-owner-of-wpf-window) to keep WPF happy. – Hans Passant Feb 25 '16 at 00:40

1 Answers1

3

Shoutout to Hans Passant who directed me to the answer in the comment above.

Excel's Application.Hwnd gave me the handle for the excel window. To convert that to a System.Windows.Window object I used the following:

var helper = new System.Windows.Interop.WindowInteropHelper(view);
helper.Owner = (System.IntPtr)excel.Application.Hwnd;

In this way, my view is now designated as a child of the main excel window.

Brandon
  • 89
  • 9