Tuesday, September 22, 2009

WPF #1 - How to get windows handle

Hi guys,

My first post at my not so recently created blog, Between APIs!
Here I intend to discuss and talk only about my programming daily issues, tips, problems, solutions. If it matter for a developer than its posted here!

My first one is all about starting WPF.
I've stumbled with this problem when starting a new WPF library that would be used by a WindowsForm application. How to get the current WF window handle to use as owner?

Very simple:
MyWpfWindow myWindow = new MyWpfWindow();
WindowInteropHelper windowHelper = new WindowInteropHelper(myWindow).Handle;
windowHelper.Owner = myOldWfForm.Handle;
myWindow.ShowDialog();

Source:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a62f912f-a28e-416b-b0f1-065ae9d6cc01

Hope you guys enjoy the blog!