C# 中的 Listview 不显示任何属性

Listview in C# does not show any properties

我正在尝试使用简单的 ListView。我在我的 XAML 文件中拖了一个,命名它,并试图在代码中访问它。然而,像 .Column 这样的所有属性都不可用。

当我尝试通过代码制作列表视图时,它也不起作用。我在这里错过了什么?我添加了 System.Windows.Forms

System.Windows.Forms.ListView testView = new System.Windows.Forms.ListView();

(System.Windows.Forms.ListView)lsView.Column // Can't find the property at all..

其他对象工作得很好,例如 ListBox。我正在使用 WPF .NET 框架

您应该在 WPF 中使用 System.Windows.Controls.ListView。它有一个 View 属性,您可以将其设置为 GridView,后者又具有 Columns 属性:

System.Windows.Controls.ListView testView = new System.Windows.Controls.ListView();
System.Windows.Controls.GridView gridView = new System.Windows.Controls.GridView();
testView.View = gridView;

gridView.Columns.Add(new GridViewColumn() { Header = "...", DisplayMemberBinding = new Binding("Property") });