控制台应用程序中的 WPF 表单 [英] WPF form in a console app

查看:44
本文介绍了控制台应用程序中的 WPF 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个控制台应用程序,该应用程序加载一个 dll 并从该 dll 调用一个方法,该方法创建一个 WPF 表单.所以我只是调用 Program.Execute() 方法,它完成了表单的所有创建.所有反射业务进展顺利,但表格没有出现.

Im running a console app that loads a dll and calls a method from that dll that creates a WPF form. So I'm just calling to Program.Execute() method and it does all the creation of the form. All reflection business goes well, but the form does not appear.

我有人告诉这是因为控制台应用程序没有 Windows 消息循环,但我确信有一种方法可以模拟它.例如,我尝试使用 System.Windows.Threading.DispatcherFrame,但无济于事 - 表单仍然没有显示.

I've been told that this is because a console app does not have a windows message loop, but I'm sure there is a way to simulate that. For example, I tried playing with System.Windows.Threading.DispatcherFrame, but to no avail - the form still does not show up.

有其他人遇到过这个问题吗?

Did anyone else face this problem?

推荐答案

只需调用 WPF 的 Application.Run().或 Window.ShowDialog(),同样的事情.您还必须在 Main() 方法上应用 [STAThread] 属性.

Just call WPF's Application.Run(). Or Window.ShowDialog(), same thing. You will also have to apply the [STAThread] attribute on your Main() method.

这篇关于控制台应用程序中的 WPF 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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