如何在WPF用户控件之间传递数据? [英] How to pass data in between WPF user controls ?

查看:1665
本文介绍了如何在WPF用户控件之间传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Helle everyone,

我正在使用WPF表格进行桌面应用。我需要从另一个用户控件的按钮单击打开一个用户控件,我需要将数据从一个用户控件传递到另一个用户控件。我该怎么做 ?

谢谢!



我的尝试:



试图从另一个打开用户控件,但showdialogue方法不会打开用户控件。

Helle everyone,
I am using WPF forms for desktop application. I need to open one user control from the button click of another user control and I need to pass data from one user control to another. How do I do it ?
Thanks !

What I have tried:

Tried to open the user control from the other, but the showdialogue method does not open the user control.

推荐答案

在控件中创建一个事件按钮。

持有两个控件的容器处理事件,通过属性读取数据,并通过其属性将其传递给另一个控件。

这样,既不控件需要知道另一个的存在,容器决定数据发生了什么,好的OOP练习也是如此。

这里有一个例子:在两种形式之间传递信息,第3部分:儿童到儿童 [ ^ ]。它关注WinForms应用程序中的表单,但原则 - 甚至代码 - 完全相同。
Create an event in the control holding the button.
The container holding the two controls handles the event, reads the data via a property, and passes it to the other control via its properties.
That way, neither control needs to know about the existence of the other and the container decides what happend to the data, as is good OOPs practice.
There is an example here: Transferring information between two forms, Part 3: Child to Child[^]. It's concerned with forms in a WinForms application, but the principles - and even the code - is exactly the same.


这篇关于如何在WPF用户控件之间传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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