简体   繁体   English

如何在一个用户控件中将textbox.text设置为与另一个用户控件中的textbox.text相等?

[英]How can I set the textbox.text in one user control equal to the textbox.text in another?

I have a .NET WPF browser app page with 2 user controls. 我有一个带有2个用户控件的.NET WPF浏览器应用程序页面。 I want textbox.text in user control 2 to equal textbox.text in user control 1. 我希望用户控件2中的textbox.text等于用户控件1中的textbox.text。

I have tried userctrl2.textbox1.text = userctrl1.textbox.text , but it doesn't work. 我已经尝试过userctrl2.textbox1.text = userctrl1.textbox.text ,但是它不起作用。

I'm used to Windows Forms-based applications, however WPF works a bit differently. 我已经习惯了基于Windows Forms的应用程序,但是WPF的工作方式却有所不同。 How can I set the textbox.text in user control 2 equal to the textbox.text in user control 1? 如何设置用户控件2中的textbox.text等于用户控件1中的textbox.text?

Why not do it the WPF way? 为什么不使用WPF方法呢?

First text box control should bind to a property using two way binding. 第一个文本框控件应使用两种方式绑定到属性。

Second text box control should bind to a property using one way binding. 第二个文本框控件应使用一种方法绑定到属性。

When you type in a first text box, it will update the underlying property, and this will in turn notify the second text box control that the property changed. 当您在第一个文本框中键入内容时,它将更新基础属性,这将依次通知第二个文本框控件该属性已更改。

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

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