简体   繁体   English

缺少WPF中的ListView.Columns

[英]Missing ListView.Columns in WPF

I'm writing an application with a ListView in C# WPF. 我正在使用C#WPF中的ListView编写应用程序。 I was wondering if I was missing a reference of something, because I get this error all the time: 我想知道我是否错过了某个东西的引用,因为我总是得到这个错误:

'System.Windows.Controls.ListView' does not contain a definition for 'Columns' and no extension method 'Columns' accepting a first argument of type 'System.Windows.Controls.ListView' could be found (are you missing a using directive or an assembly reference?)` 'System.Windows.Controls.ListView'不包含'Columns'的定义,也没有扩展方法'Columns'接受类型为'System.Windows.Controls.ListView'的第一个参数'(你是否缺少using指令)或汇编参考?)`

It's not only with MyListview.Colums but also when I want to add a multi-column item to my ListView, for example by following this . 这不仅与MyListview.Colums而且当我想通过下面的多列项添加到我的ListView,例如这个 MyListView.Items.Add("Column1Text").SubItems.AddRange(row1); This gives me the same error for SubItems 这给SubItems带来了同样的错误

It's hard for me to explain, so if something isn't clear you can ask. 我很难解释,所以如果不清楚你可以问。

Edit: With a lot of help from you and some Googling skills I found a solution. 编辑:在你的帮助和一些谷歌搜索技能的帮助下,我找到了解决方案。 My XAML code: 我的XAML代码:

<Grid>
    <ListView x:Name="MyListView"
        <ListView.View>
            <GridView x:Name="MyGridView">
                <GridViewColumn Header="#" DisplayMemberBinding="{Binding Number}" Width="24" />
                <GridViewColumn Header="Song" DisplayMemberBinding="{Binding Song}" Width="390" />
            </GridView>
        </ListView.View>
    </ListView>

and here is how to add an item: 以下是添加项目的方法:

        MyListView.Items.Add(new { Number = 1, Song = "My first song" });
        MyListView.Items.Add(new { Number = 2, Song = "My second song" });

This was my first time working with bindings, but I learned a lot! 这是我第一次使用绑定,但我学到了很多东西!

afaik, GridView has columns, ListView does not. afaik,GridView有列,ListView没有。

See MSDN : 请参阅MSDN

Represents a view mode that displays data items in columns for a ListView control. 表示以ListView控件的列显示数据项的视图模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM