如何将多个值数据绑定到WP7中的单个TextBlock.Text? [英] How to data bind multiple values to a single TextBlock.Text in WP7?

查看:154
本文介绍了如何将多个值数据绑定到WP7中的单个TextBlock.Text?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将两个属性绑定到单个TextBlock.Text(例如,名字和姓氏或当前值和最大值)?

How can I bind 2 properties to a single TextBlock.Text (eg. first name and last name or current value and max value)?

类似于: / p>

something like:

// IValueConverter
public object Convert( .... )
{
    return string.Format("{0} (max: {1})", currentValue, maxValue);
}

问题是我希望TextBlock.Text在 currentValue maxValue 已更改。那么如何使用数据绑定来监听来自2个或更多属性的更改?

The problem is I want TextBlock.Text to be updated when currentValue or maxValue has changed. So how can I listen to changes from 2 or more properties using data binding?

有没有另外一种方法比用户使用 IValueConverter

Is there another way than usering IValueConverter?

推荐答案

Silverlight 3(在其上构建Windows Phone 7框架)不支持MultiBinding,这是你将用来实现你所需要的。但是,有一个解决方案解决方案,您可以使用在 MultiBinding for Sivlerlight 3 中的描述也可以使用WP7。

Silverlight 3 (on which the Windows Phone 7 framework is built) doesn't support MultiBinding, which is what you would use to achieve what you need. However, there is a workaround solution that you can use described in the post MultiBinding for Sivlerlight 3, which should also work on WP7.

或者,您可以扩展视图模型(或至少是您所暴露的属性),以显示一个聚合值并引发的属性财产变更通知,当更改。

Alternatively, you could extend your view model (or at least the properties that you are exposing) to expose a property that aggregates your values and raises property change notification when either changes.

这篇关于如何将多个值数据绑定到WP7中的单个TextBlock.Text?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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