Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF modeless dialog from MS Excel add-in

A WPF form that I launch from a WinForms window showed up with all textboxes as uneditable when launched as a modeless dialog. I used ElementHost.EnableModelessKeyboardInterop to tackle the issue & it worked there.

I am also opening the same WPF UI from an MS Excel as an add-in. The EnableModelessKeyboardInterop hack doesn't work there. Whenever I try to edit my WPF textbox, the focus shifts to Excel and the keyboard input is rendered on Excel instead of on my WPF textbox. Any ideas on how to fix this?

P.S. - This is in continuation to my earlier question on SO: WPF modeless dialog renders textbox uneditable

like image 298
aliensurfer Avatar asked May 03 '11 12:05

aliensurfer


1 Answers

Solved it, courtesy of this link: Running WPF Application with Multiple UI Threads

         var thread = new Thread(() =>
            {
                var wpfWindow = new WPFWindow();
                wpfWindow.Show();
                wpfWindow.Closed += (sender2, e2) => wpfWindow.Dispatcher.InvokeShutdown();

                Dispatcher.Run();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
like image 152
aliensurfer Avatar answered Oct 19 '22 09:10

aliensurfer