In my latest project, I have a ListView
that is bound to an ObservableCollection
. This ObservableCollection
contains a number of objects of my class SongData
:
public class SongData
{
public int Id { get; set; }
public string Title { get; set; }
public string Artist { get; set; }
}
These objects are filled with data derived from a SQLite database, and the property Id
contains the primary key for that record. Obviously, I don't want to show this id in my ListView. However, I do need this id when I handle a DoubleClick event on the ListView.
My current xaml code is:
<ListView Margin="12,41,12,12" Name="lvwOverview" SelectionMode="Single" ItemsSource="{Binding SongCollection}" MouseDoubleClick="lvwOverview_MouseDoubleClick">
<ListView.View>
<GridView>
<GridViewColumn Width="200" Header="Title" DisplayMemberBinding="{Binding Title}"></GridViewColumn>
<GridViewColumn Width="200" Header="Artist" DisplayMemberBinding="{Binding Artist}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Now, I would like to be able to get the id (for use with the database), when the user doubleclicks on a ListViewItem. Any ideas on how to do that?