问题描述
我正在开发一个应用程序的触摸屏。我有与所述内容的新播放,然后示出了用于用户输入他的名字的文本框键盘按钮的形式。现在我需要当我关闭(或在输入名称)从父窗口的按钮更改内容,用户键入的名称。但我不能做一个绑定到父..我该怎么办呢?
I'm developing a touchscreen app. I have a form with buttons with the content "new player" and then a keyboard with a textbox is shown for the user to enter his name. Now I need that when I close (or while inputting the name) the button from the parent window change the content to the name that the user typed. But I cant make a binding to the parent.. how can I do it??
推荐答案
您实施WPF应用程序的模型 - 视图 - 视图模型模式,或使用数据绑定呢?
Are you implementing the Model-View-ViewModel pattern in your WPF application, or using databinding at all?
您不必使用MVVM,但你确实应该以某种方式使用数据绑定。
You don't have to use MVVM, but you should really be using databinding in some fashion.
通过数据绑定,你该按钮的内容有些对象(视图模型在MVVM)的字符串属性绑定。该对象需要实现 INotifyPropertyChanged的
接口。您可以绑定子窗口同一对象的相同属性的文本框。
With databinding, you'd bind the button content to a string property of some object (a view-model in MVVM). That object needs to implement the INotifyPropertyChanged
interface. You can bind the textbox on the child window to the same property of the same object.
通过在地方,该按钮会自动更新,当用户在一个新的球员的名字。
With that in place, the button will be updated automatically when the user types in a new player name.
如果您需要更多的信息,请发表评论,我会很高兴来阐述。
If you need more details, please comment and I'll be glad to elaborate.
这篇关于从子窗口WPF C#更改按钮的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!