列表视图win8的XAML如何创建列? [英] Listview win8 xaml how to create columns?
本文介绍了列表视图win8的XAML如何创建列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我想在ListView创建3列。
Hi I am trying to create 3 columns in a ListView.
我读到这,但我想设置每一列中的数据在程式设计C#:
I read this but I want to set the data in each column programtically in C#:
<一个href=\"http://stackoverflow.com/questions/10869715/how-to-display-data-in-rows-and-columns-xaml-windows-8\">how以显示以行和列的XAML窗口数据8
例如我想歌手名,歌曲名和歌手。
For example I want artist name, song name and artist.
推荐答案
假设你有这样的事情来存储你的数据:
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;}
}
和与定义(如您所提供的链接)一个DataTemplate,只是给你一个的ListView名字一个ListView:
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>
然后,从code-身后,这只是一个案例:
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;
这篇关于列表视图win8的XAML如何创建列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文