Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding 2 ObservableCollections to Listview
    text
    copied!<p>I'm new to WPF, and having trouble with the binding, have been searching for difference solutions, but nothing have helped. Got 2 Observable Collections, I want to be binded into to different columns of a listview. XAML code: </p> <pre><code>&lt;GroupBox Header="Search results" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Height="727" Width="739" FontFamily="Malgun Gothic" FontSize="24"&gt; &lt;ListView x:Name="ListView1" HorizontalAlignment="Left" Width="729" FontFamily="Malgun Gothic" FontSize="24" Background="{x:Null}" Margin="0,0,-2,0" ItemsSource="{Binding ElementName=Search, Path=Library}"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Header="Song name" DisplayMemberBinding="{Binding Track}" Width="550"/&gt; &lt;GridViewColumn Header="Artist" DisplayMemberBinding="{Binding Artist}" Width="170"/&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;ListView.DataContext&gt; &lt;Classes:Library/&gt; &lt;/ListView.DataContext&gt; &lt;Classes:Library Text=""/&gt; &lt;/ListView&gt; &lt;/GroupBox&gt; </code></pre> <p>From xaml.cs</p> <pre><code> Library CallSearch = new Library(); Playlist Songs = new Playlist(); private void Button_Click_2(object sender, RoutedEventArgs e) { CallSearch.Text = textSearch.Text; CallSearch.Search(); } </code></pre> <p>From Class:</p> <pre><code> private ObservableCollection&lt;string&gt; track = new ObservableCollection&lt;string&gt;(); private ObservableCollection&lt;string&gt; artist = new ObservableCollection&lt;string&gt;(); public ObservableCollection&lt;string&gt; Track { get { return track; } set { track = value; } } public ObservableCollection&lt;string&gt; Artist { get { return artist; } set { artist = value; } } </code></pre> <p>Inside a public void:</p> <pre><code> foreach (DirectoryInfo diNext in dirs) { foreach (FileInfo test in diNext.GetFileSystemInfos("*"+tb+"*"+".mp3", SearchOption.AllDirectories)) { u.Read(test.FullName); Track.Add(u.Title); Artist.Add(u.Artist); } } </code></pre> <p>What I'm missing?</p> <p>UPDATE FOR NIT: System.Windows.Data Error: 40 : BindingExpression path error: 'Albums' property not found on 'object' ''Library' (HashCode=36404074)'. BindingExpression:Path=Albums; DataItem='Library' (HashCode=36404074); target element is 'ListView' (Name='ListView1'); target property is 'ItemsSource' (type 'IEnumerable') System.Windows.Data Error: 40 : BindingExpression path error: 'Track' property not found on 'object' ''Library' (HashCode=40706798)'. BindingExpression:Path=Track; DataItem='Library' (HashCode=40706798); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String') System.Windows.Data Error: 40 : BindingExpression path error: 'Artist' property not found on 'object' ''Library' (HashCode=40706798)'. BindingExpression:Path=Artist; DataItem='Library' (HashCode=40706798); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload