是否可以将两个源属性绑定到一个控件属性? [英] Is it possible to bind two source properties to one control property?

查看:188
本文介绍了是否可以将两个源属性绑定到一个控件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用WPF,可以通过单向绑定将两个源属性绑定到一个控件属性(即textbox.text)?我想让用户在文本框中输入一个值,并将该值推送到源数据文本中的两个不同的属性。我的解决方法是创建一个虚拟属性,并让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.

推荐答案

代理,如本博客文章中所述:

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:


  1. 使用x定义一个TextBox:Name = tb

  2. 将TextBox.Text绑定到Prop1

  3. 使用In ={Binding Text,ElementName = tb}添加代理元素,Out ={Binding Prop2}(不在TextBox内)

这样一来,您可以将Prop1和Prop2与tb.Text同步。

This way, you will have Prop1 and Prop2 synchronized with tb.Text.

这篇关于是否可以将两个源属性绑定到一个控件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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