绑定到集合的观点,只是调用toString()在WPF [英] Bind to a collection's view and just call ToString() in WPF
问题描述
我绑定的GridView对象的集合是这样的:
I'm binding a GridView to a collection of objects that look like this:
public class Transaction
{
public string PersonName { get; set; }
public DateTime TransactionDate { get; set; }
public MoneyCollection TransactedMoney { get; set;}
}
MoneyCollection
,是 MyMoney
键入对象
在我的GridView的,我只是想绑定到 MoneyCollection
的的ToString列()
方法。然而,直接约束它的 TransactedMoney
属性使每个条目显示文本(集合),而的ToString()
方法不会被调用。
In my GridView, I just want to bind a column to the MoneyCollection
's ToString()
method. However, binding it directly to the TransactedMoney
property makes every entry display the text "(Collection)", and the ToString()
method is never called.
注意的我不想绑定到项MoneyCollection 的,我想直接自身绑定到财产,只需要调用的ToString()
就可以了。
Note that I do not want to bind to the items in MoneyCollection, I want to bind directly to the property itself and just call ToString()
on it.
据我所知,这是绑定到集合的默认视图。所以我的问题是 - 我怎么可以把它绑定到集合中的这样一种方式,它调用的ToString()
方法就可以了。
I understand that it is binding to the collection's default view. So my question is - how can I make it bind to the collection in such a way that it calls the ToString()
method on it?
这是我的第一个WPF项目,所以我知道这可能是一个有点noobish,但三分球将是非常欢迎的。
This is my first WPF project, so I know this might be a bit noobish, but pointers would be very welcome.
推荐答案
编写调用的ToString()绑定的集合,并返回,并使用了XAML绑定表达式这个转换器中的的IValueConverter
实施
Write a IValueConverter
implementation that calls ToString() on the bound collection and returns it and use this converter in the XAML binding expression.
这篇关于绑定到集合的观点,只是调用toString()在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!