如何将两个属性绑定到单个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?
发布评论