开发者

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: W开发者_运维百科PF modeless dialog renders textbox uneditable


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜