Listview win8 xaml如何创建列? [英] Listview win8 xaml how to create columns?

查看:21
本文介绍了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如何创建列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆