将两个值从window2传递给window1 [英] Pass two values from window2 to window1

查看:75
本文介绍了将两个值从window2传递给window1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



在WPF中,我从window1打开window2,点击按钮保持window1打开。当我关闭window2时,我想在window1中显示2个值。如何实现?



谢谢

Hello,

In WPF, I open window2 from window1 with a button click keeping window1 open. When I close window2, I want to display 2 values in window1. How can this be achieved?

Thanks

推荐答案

这是关于windows之间协作的热门问题。最强大的解决方案是在窗口类中实现适当的接口,并传递接口引用而不是引用Window的整个实例。有关更多详细信息,请参阅我以前的解决方案:如何以两种形式复制列表框之间的所有项目 [ ^ ]。



(对不起,上面引用的页面是关于 System.Windows.Forms ,但想法完全一样。



另请参阅其他解决方案在这个讨论中。如果应用程序足够简单,解决方案就像在一个窗口中声明一些 internal 属性并将引用传递给一个窗口的实例一样简单另一个窗口的实例。对于更复杂的项目,这种违反严格封装的样式和松散耦合可能会增加代码的意外复杂性并引发错误,所以以及-E ncapsulated解决方案将是更可取的。



请参阅:

http://en.wikipedia.org/wiki/Accidental_complexity [ ^ ],

http://en.wikipedia.org/wiki/ Loose_coupling [ ^ ]。



-SA
This is the popular question about collaboration between windows. The most robust solution is implementation of an appropriate interface in window class and passing the interface reference instead of reference to a "whole instance" of a Window. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

(Sorry, the page referenced above is about System.Windows.Forms, but the ideas are exactly the same.

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one window and passing a reference to the instance of one window to the instance of another window. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA


感谢您的回复。我在提供的链接中尝试了代码,但这似乎不起作用。此外,当window2处于活动状态时,我的window1处于打开状态。当window2关闭时,仍然处于活动状态的window1应显示值。这是我的要求。
Thanks for the reply. I tried the code in the link provided, but that doesn't seem to work. Moreover, my window1 is open when window2 is active. When window2 is closed, window1, which is still active should display the values. This is my requirement.


这篇关于将两个值从window2传递给window1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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