Assuming you have something like this to store your data:
public class SongDetails
{
public string ArtistName {get; set;}
public string SongName {get; set;}
public string Artist {get; set;}
}
And a ListView with a DataTemplate defined (as in the link you provided), just give your ListView a name:
<ListView Name="ListViewSongs">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="500" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Artist}" />
<TextBlock Grid.Column="1" Text="{Binding ArtistName}" />
<TextBlock Grid.Column="2" Text="{Binding SongName}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Then, from the code-behind, it's just a case of:
var songDetails = new[]
{
new SongDetails {Artist = "a1", ArtistName = "a2", SongName = "a3"},
new SongDetails {Artist = "b1", ArtistName = "b2", SongName = "b3"}
};
ListViewSongs.ItemsSource = songDetails;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…