WPF从MS Excel的无模式对话框加载 [英] WPF modeless dialog from MS Excel add-in
问题描述
一个WPF形式,我启动从一个WinForms窗口显示了所有的文本框
作为不可编辑的时候作为一个无模式对话框启动。我用了
ElementHost.EnableModelessKeyboardInterop
来解决这个问题和放大器;它在那里工作。
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.
我也是从一个MS Excel中打开相同的WPF UI作为一个加载项。
该 EnableModelessKeyboardInterop
破解这里是行不通的。每当我试着
编辑我的WPF的文本框,将重点转移到Excel和键盘输入
呈现在Excel中,而不是在我的WPF文本框。关于如何解决此问题的任何想法?
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。 - 这是在延续我先前的问题上这样: WPF无模式对话框呈现文本框不可编辑一>
P.S. - This is in continuation to my earlier question on SO: WPF modeless dialog renders textbox uneditable
推荐答案
解决了这个问题,礼貌这个环节:的运行与WPF应用程序的多个UI线程
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();
这篇关于WPF从MS Excel的无模式对话框加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!