如何从位于另一个页面上的 TextBox 获取数据? [英] How to get data from TextBox, which located on the other page?

查看:22
本文介绍了如何从位于另一个页面上的 TextBox 获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 MainPaqe.cs (MainPaqe.xaml) 和 Periodic_Request.cs (Periodic_Request.xaml),此外,Periodic_Request.xaml 有名为 TxtBlock_numRequestTextBox 和名为 CmbBox_lvlPriorityCombobox代码> 可能有 3 个选项.

I have MainPaqe.cs (MainPaqe.xaml) and Periodic_Request.cs (Periodic_Request.xaml), in addition, Periodic_Request.xaml has TextBox with name TxtBlock_numRequest and Combobox with name CmbBox_lvlPriority with possible 3 options.

问题是如何从 MainPaqe.cs 中的 TextBoxCombobox 获取用户书写的数字或字符串.我需要在按下 button 后获取所有这些信息.

The problem is how get user written numbers or strings from TextBox and Combobox in the MainPaqe.cs. I need to get all this information after pressing button.

有人建议使用 MVVM ,但老实说我无法理解.这就是为什么我需要你的帮助.

Someone has advised to use MVVM , but honestly I can`t understand it. This is why I need your help.

推荐答案

MVVM 是一种架构设计模式,它促进了关注点分离 设计模式.在开发 WPF 应用程序时使用 MVVM 模式是非常有利的,尽管不是强制性的.在您的应用程序中实现 MVVM 模式可能需要更多的努力和思考,至少在第一次使用它时,比使用 WPF 旧的 WinForms 代码隐藏方式.

MVVM is an architectural design pattern which facilitates the Separation of Concerns design pattern. It is highly advantageous to make use of the MVVM pattern when developing your WPF applications although not compulsory. Implementing the MVVM pattern in your application can require a little more effort and thought, at least when first using it, than is required when using WPF the old WinForms code-behind way.

1) 如果您想走 MVVM 路线,请查看 EventAggregatorMediator\Message Bus 模式.这些允许相互通信,而无需彼此直接了解.

1) If you want to go down the MVVM route, take a look at the EventAggregator and Mediator\Message Bus patterns. These allow classes to communicate with one another without them requiring direct knowledge of one another.

2) 或者,如果您愿意继续使用 WinForms 路线,请查看 EventHandler 委托.这将允许您在一个 class 中引发一个 event 可以被另一个 class 检测到.

2) Alternatively if you are happy to continue using the WinForms route, take a look at the EventHandler<T> delegate. This will allow you to raise an event in one class which can be detected by another class.

这篇关于如何从位于另一个页面上的 TextBox 获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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