从WPF用户控件调用Windows窗体内的方法 [英] Call from WPF user control to a method inside a windows form

查看:679
本文介绍了从WPF用户控件调用Windows窗体内的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户控件在项目中并且该表单在另一个项目中,我可以调用父表单吗?

Can i call to the parent form whein the user control is in project and the form is in another project

推荐答案

从用户控件调用托管页面方法是这不是一个好方法,在这种情况下,您需要将表单对象传递给用户控件.取而代之的是,您可以在用户控件中定义一个委托和事件,并在容器表单中注册该事件.在事件定义中,您可以调用本地方法.您只需要从WPF用户控件引发事件即可.

Calling hosting page method from a user control is not a good approach, in that case you need to pass the form object to the user control. Instead of this you can define a delegate and event in the user control and register that event in the container form. In the event definition you can call the local method. You just need to raise the event from the WPF user control.

mharakeh1写道:
mharakeh1 wrote:

如果用户控件位于项目中并且该表单位于另一个项目中,我可以调用父表单吗?

Can i call to the parent form whein the user control is in project and the form is in another project



控件在同一项目中还是在其他项目中,没有任何区别.



It doesn''t make any difference if the control is in same project or in a different project.


这篇关于从WPF用户控件调用Windows窗体内的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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