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

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

问题描述

我从 WinForms 窗口启动的 WPF 表单显示所有文本框作为非模式对话框启动时不可编辑.我用了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 无模式对话框呈现文本框不可编辑

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

推荐答案

已解决,此链接提供:使用多个 UI 线程运行 WPF 应用程序

         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天全站免登陆