Listview win8 xaml how to create columns?(Listview 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#:
如何按行显示数据和列 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>
那么,从代码隐藏来看,这只是一个例子:
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;
这篇关于Listview win8 xaml如何创建列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Listview win8 xaml如何创建列?
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
