Bind to a collection view and just call ToString () in WPF

I bind 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;}
}

MoneyCollectionjust inherits from ObservableCollection<T>and is a collection of type objects MyMoney.

In my GridView, I just want to bind a column to a method MoneyCollection ToString(). However, binding it directly to the property TransactedMoneymakes each record display the text "(Collection)", and the method is ToString()never called.

Please note that I do not want to bind to elements in MoneyCollection, I want to bind directly to the property itself and simply call ToString()on it.

I understand that it is tied to the default view for the collection. So my question is: how can I bind it to a collection so that it invokes a method on it ToString()?

This is my first WPF project, so I know it might be a bit noobish, but pointers would be very welcome.

+3
source share
2 answers

Write an implementation IValueConverterthat calls ToString () in the associated collection and returns it and uses this converter in the XAML binding expression.

+3
source

StringRepresentation - MyMoney. , - MyMoneyViewModel, . . ...!

+4

Source: https://habr.com/ru/post/1747453/


All Articles