如何从C#winform中的Wpf托管元素访问父窗体控件 [英] How to access parent form control from Wpf hosting element in C# winform

查看:86
本文介绍了如何从C#winform中的Wpf托管元素访问父窗体控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#winform中的应用程序

在usercontrol中托管的Wpf元素。我想在父窗体上设置标签,托管wpf元素。我尝试过构造函数但是还不可能。我也为这个标签制作了属性,并用wpf代码访问但不可能。

请有人建议我正确的解决方案。
父表单上的
(CHDatabaseManagement)构造函数的代码是

Application in C# winform
Wpf element hosted in usercontrol. I want to set label on parent form on which wpf element is hosted. I tried through constructor but is not possible yet. I also made properties for this label and accessed in wpf code but not possible.
Please anyone suggest me proper solution.
on Parent form(CHDatabaseManagement) Code for constructor is

public CHDatabaseManagement(string Displaylbl)
      {
          InitializeComponent();
          DisplayLabel.Text = Displaylbl;
      }







------

在wpf表单代码是

CHDatabaseManagement chdab = new CHDatabaseManagement();

但是在编译时,标签显示默认文本值




------
and on wpf form code is
CHDatabaseManagement chdab = new CHDatabaseManagement("");
but when compile then label shows default text value

推荐答案

完全错误的方法。子控件永远不应该尝试更改父容器中的控件。关注的是它本身和它本身。



如果有数据需要从链上发回,请使用事件来完成。 paren容器或表单应决定如何处理数据,而不是子控件。
Wrong approach entirely. A child control should never try to change a control in a parent container. It's concern is with itself and itself alone.

If there is data that needs to be sent back up the chain, use an event to do it. The paren container or form should decide what to do with the data, not the child controls.


这篇关于如何从C#winform中的Wpf托管元素访问父窗体控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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