绑定一个元素两个来源 [英] Bind an element to two sources
问题描述
我目前有两个文本框,其中接受任何数字。我有一个文本块,它需要进入两个数字并计算平均值。
I currently have two text boxes which accept any number. I have a text block that takes the two numbers entered and calculates the average.
我在想,如果有我可以结合这个文本块到两个文本框和利用自定义转换计算平均值的方法吗?我目前正在赶上文本改变了这两个文本框事件,并计算平均值的方式,但我下的假设,数据绑定会更有效,更简单。
I was wondering if there was a way I could bind this text block to both text boxes and utilize a custom converter to calculate the average? I currently am catching the text changed events on both text boxes and calculating the average that way, but I am under the assumption data binding would be more efficient and easier.
推荐答案
您正在寻找的<$c$c>MultiBinding$c$c>.
You're looking for MultiBinding
.
您 XAML
会是这个样子:
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myConverter}">
<Binding Path="myFirst.Value" />
<Binding Path="mySecond.Value" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
随着 myConverter
, myFirst.Value
替换合理和 mySecond.Value
。
这篇关于绑定一个元素两个来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!