简体   繁体   English

将值从一个用户控件传递到另一个用户控件

[英]Pass Values from one user control to another

I am working on a WPF application, and I looking for a solution on how to pass a integer values either generated or pulled from a database across user controls我正在开发一个 WPF 应用程序,我正在寻找一种解决方案,说明如何通过用户控件从数据库中生成或提取 integer 值

For example例如

  • Let's say there is a main window called WinA假设有一个名为WinA的主要 window
  • it hosts 2 user controls, one called CustomerDetails and another CustomerOrder它托管 2 个用户控件,一个称为CustomerDetails ,另一个称为CustomerOrder
  • the CustomerDetails user control has a CustomerID textbox and a button and some unimportant textboxes to insert values into the database CustomerDetails用户控件有一个CustomerID文本框和一个按钮以及一些用于将值插入数据库的不重要的文本框
  • CustomerOrder has an OrderID textbox CustomerOrder有一个OrderID文本框

We create a customer profile on CustomerDetails .我们在CustomerDetails上创建客户资料。 When I click the button (on CustomerDetails ), it would not only save values to the database but also open the CustomerOrder user control and should take the value from the CustomerID textbox and pass it into the OrderID textbox当我单击按钮(在CustomerDetails上)时,它不仅会将值保存到数据库中,还会打开CustomerOrder用户控件,并且应该从CustomerID文本框中获取值并将其传递到OrderID文本框中

  • Saving values into database, opening a new user control ✔ Done将值保存到数据库中,打开一个新的用户控件 ✔ 完成
  • Passing value into into another user control ❌ Cannot even start将值传递到另一个用户控件❌甚至无法启动

You can create a variable using get and set inside the code for the control.您可以在控件代码中使用 get 和 set 创建变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM