是否可以绑定两个源属性一个控制的财产? [英] Is it possible to bind two source properties to one control property?
问题描述
使用WPF,是可以绑定两个源属性,通过单向绑定,一个控件的属性(即textbox.text)?我想有用户输入文本框的值,并有该值在源的DataContext推到两个不同的属性。我的解决办法是建立一个虚拟的财产,有setter方法手工设置两个值。
Using WPF, is it possible to bind two source properties, via one-way binding, to one control property (ie textbox.text)?? I'd like to have the user input a value in a textbox and have that value pushed to two different properties in the source datacontext. My workaround is to create a dummy property and have the setter set the two values manually.
推荐答案
您可以使用一种binding-代理,在这个博客帖子描述:
You could use kind of binding-proxy, as described in this blog post:
的 http://www.11011.net/wpf-binding-properties
然后,只需按照以下步骤操作,例如:
Then just follow these steps for example:
- 定义为x文本框:名称= TB
- 绑定TextBox.Text来为prop1
<李>添加代理服务器的元素用在={结合文本,的ElementName = TB},时间={结合Prop2}(不中,但文本框旁)
这样,您将拥有为prop1和Prop2与tb.Text同步。
This way, you will have Prop1 and Prop2 synchronized with tb.Text.
这篇关于是否可以绑定两个源属性一个控制的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!