How can I set the Owner property of the WPF window to the handle of our main form?

Platform: WPF| Category: Message Loops Between

We can do this by using WindowInteropHelper. This can be done with the following code snippets.


[C#]
var wpfWindow = new MainWindow();
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(wpfWindow);
            windowInteropHelper.Owner = this.Handle;
            wpfWindow.Show();

Note: While using the previous code in the form, add the following WPF assemblies to show the WPF window.

  • PresentationCore
  • PresentationFramework
  • WindowsBase

Reference link: https://stackoverflow.com/questions/32701680/setting-a-form-as-owner-for-a-window

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.