来自MS Excel加载项的WPF无模式对话框 [英] WPF modeless dialog from MS Excel add-in

查看:287
本文介绍了来自MS Excel加载项的WPF无模式对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从WinForms窗口启动的WPF表单显示为所有文本框$​​ b $ b,作为无模式对话框启动时不可编辑。我使用
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 hack不起作用。每当我尝试
编辑我的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?

- 这是继续我之前的关于SO的问题: WPF无模式对话框渲染textbox uneditable

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

推荐答案

解决方案,由此链接提供:运行具有多个UI线程的WPF应用程序

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

这篇关于来自MS Excel加载项的WPF无模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆