处理从一个独立的WPF应用程序一个WinForms按钮的Click事件 [英] Handling a WinForms button's Click event from a separate WPF application

查看:111
本文介绍了处理从一个独立的WPF应用程序一个WinForms按钮的Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:所以我有两个应用程序:一个是的WinForms,另一个是WPF。我试图找出如何点击一个按钮,在WinForms应用程序,和那些点击WPF应用程序响应。

Summary: So I have two applications: one is WinForms and the other is WPF. I am trying to figure out how to click a button in the WinForms app and have the WPF app respond to that click.

因此​​,为了获得更详细的,我的工作在现有的WinForms应用程序,增加新的功能。对于这些功能之一,我需要创建一个单独的WPF应用程序与坐在WinForms应用程序的顶部,可以得出在WinForms应用程序用户的InkCanvas。

So to get more detailed, I am working on an existing WinForms application, adding new features. For one of those features, I needed to create a separate WPF application with an InkCanvas that sits on top of the WinForms application and allows the user to draw over the WinForms app.

我对WinForms应用程序3按钮,是为了控制InkCanvas:一是使绘图,以使能擦除,和一个清除画布。我需要搞清楚的是如何处理这3个按钮的Click事件中的WPF应用程序。

I have 3 buttons on the WinForms app that are meant to control the InkCanvas: one to enable drawing, one to enable erasing, and one to clear the canvas. What I need to figure out is how to handle those 3 buttons' Click events in the WPF application.

我一直在寻找的东西像PRISM的EventAggregator(虽然我不知道这是否会独立进程之间工作)和WCF。 WCF好像是我应该使用,但我使用它没有经验,所以也进展缓慢。我所遇到的有关WCF双面打印服务的文章(的链接)(链接

I've been looking at things like PRISM's EventAggregator (although I don't know if that would work between separate processes) and WCF. WCF seems like what I should be using, but I have no experience using it, so it is slow going. I have come across articles about WCF Duplex Services (link)(link)

所以,我想我的问题是:什么是处理一个WinForms按钮的Click事件在一个单独的WPF应用程序的最佳方法?提前道歉,如果这个问题已经被问,或者是过于空泛。

So I guess my question is: what is the best approach to handling a WinForms button's Click event in a separate WPF application? Apologies in advance if this question has already been asked or if it is too vague.

推荐答案

的WinForms可以承载使用的 的ElementHost 控制,内置在的WinForms控件库。如果没有在这种情况下工作(因为您使用的是透明性),您可以尝试使用您覆盖上的应用程序之上的新的WPF窗口(见的>打开WPF窗口)。

WinForms can host WPF elements using the ElementHost control, built into the Winforms control library. If that doesn't work in this case (because you are using transparency), you can try using a new WPF window that you overlay on top of the application (see Open WPF window in WindowsForm APP).

这样,您就可以连线了事件处理程序和沟通,而不必担心IPC方法或者管理两个不同的可执行文件的应用程序生命周期。

This way you can wire up event handlers and communication without having to worry about IPC methods or managing application lifetimes between two different executables.

这篇关于处理从一个独立的WPF应用程序一个WinForms按钮的Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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