0

I'm have listView which show Name of book and first Author:

<ListView.View>
        <GridView>
            <GridViewColumn Header="Name" Width="Auto" DisplayMemberBinding="{Binding Name}" />
            <GridViewColumn Header="Author" Width="Auto" DisplayMemberBinding="{Binding Authors[0].Name}" />
        </GridView>
    </ListView.View>

But i need to show not only name first author, but all author in collection separated by commas. This is my Model:

public class Book : IModel
    {
        public Book()
        {
            Authors = new List<Author>();
            Tags = new List<string>();
        }
        public string Name { get; set; }
        public List<Author> Authors { get; set; }
        public string ISBN { get; set; }
        public int Pages { get; set; }
        public List<string> Tags { get; set; }
        public int PublicationYear { get; set; }
        public PublicationHouse PublicationHouse { get; set; }
    }

And code behind XAML:

public partial class BooksView : ListView
    {
        public BooksView()
        {
            InitializeComponent();
            ItemsSource = FilesManager.books.Values;
        }
    }
Rodion
  • 63
  • 11
  • Use a Binding Converter that converts an `IEnumerable` to string, or add another property (probably to a view model class) that already contains the result string. – Clemens Sep 11 '16 at 08:01

1 Answers1

0

What about making a separate property?

 public string MyAuthors { get {return return String.Join(", ", Authors.ToArray());} }

I would also recommend to implement INotifyPropertyChanged to avoid further problem in your Data Binding.

Mr.B
  • 3,484
  • 2
  • 26
  • 40