10

I have an excel AddIn which exposes IWin32Window as it's main UI. I want to show a WPF window that uses this as it's parent.

How do I go about doing that ?

2 Answers 2

8

You can use WindowInteropHelper to parent the WPF window appropriately:

var helper = new WindowInteropHelper(theWpfWindow);
helper.Owner = win32Window.Handle;

theWpfWindow.Show(); // This is now parented appropriately
Sign up to request clarification or add additional context in comments.

4 Comments

I have this: System.Windows.Forms.IWin32Window (note, it is NOT namespace). MainHostWindow host = new MainHostWindow(); var helper = new WindowInteropHelper(host); helper.Owner = this._mainWindow.Handle; host.Owner is NULL
@Pacman: host.Owner will stay null - you just set the interop helper as I showed, and it should parent it appropriately. If you want it modal, use ShowDialog()...
What is I want to make the Owner Window Disabled: host.Owner.IsEnabled = false ?
@Pacman: You're trying to disable Excel's main window? You won't be able to do that from an extension - better to just use ShowDialog() to open your window modally, which will prevent the user from interacting with the host until you close your window.
0

I think you need to use a WindowInteropHelper, like shown here: IWin32Window Owner For WPF Window

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.