将WPF EXE托管到WPF项目中 [英] Host WPF EXE into WPF project

查看:73
本文介绍了将WPF EXE托管到WPF项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用WindowsFormsHost将外部EXE托管到我的WPF应用程序中。

如果我主持一个WinForm应用程序这个工作正常。

当我尝试托管WPF EXE应用程序时,问题就出现了。应用程序已加载,但仅显示外部边框,黑色内容透明。

应用程序的其他部分仅在我单击上边框时加载。



我疯了...



感谢所有能帮助我的人..



这里是代码。



Hello guys,
I'm using a WindowsFormsHost to hosting an external EXE into my WPF application.
If I host a WinForm application this working good.
The problem begin when I try to host a WPF EXE application. The application is loaded, but is visualized only the external border, with a transparent on black content.
The other part of the application is loaded only when I click on the upper border.

I'm going crazy...

Thanks all those who can help me..

Here the code.

WindowsFormsHost wfh = new WindowsFormsHost();
F.Panel panel1 = new F.Panel();

Grid MainGrid = new Grid();
MainGrid.Children.Add(wfh);

TabItem Tab = new TabItem();
Tab.Content = MainGrid;
MyTabContainer.Items.Add(Tab);

ProcessStartInfo psi = new ProcessStartInfo(@"c:\app\myWPFapp.exe");
Process p = Process.Start(psi);

for (int i = 0; i < 1000; i++)
         {
           System.Threading.Thread.Sleep(10);
           p.Refresh();
           if (p.MainWindowHandle != IntPtr.Zero)
            {
             break;
            }
         }

SetParent(p.MainWindowHandle, panel1.Handle);
ShowWindow(p.MainWindowHandle, SW_SHOWMAXIMIZED);

Tab.Focus();







Davide




Davide

推荐答案

将您的WPF内容放入DLL中。实际上,您也应该为WinForms应用程序执行此操作,因为有人评论过,您尝试做的事情没有意义。这不是事情应该如何运作。



你没有帮助任何人尝试这样的怀疑黑客。多个EXE的UI应该是独立的。
Put your WPF stuff in a DLL. In fact, you should also do that for your WinForms application as someone has commented, what you are trying to do does not make sense. It is not how things are supposed to work.

You are not helping anybody be trying such suspicions hacks. The UI of multiple EXE should be independant.


你应该仔细阅读MSDN帮助页...

You should read MSDN help pages carefully...

允许您在WPF页面上托管 Windows窗体控件的元素。

An element that allows you to host a Windows Forms control on a WPF page.


这篇关于将WPF EXE托管到WPF项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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