绑定一个元素两个来源 [英] Bind an element to two sources

查看:107
本文介绍了绑定一个元素两个来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有两个文本框,其中接受任何数字。我有一个文本块,它需要进入两个数字并计算平均值。

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.

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屋!

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