简体   繁体   English

在WPF中ListView和GridView有什么区别?

[英]What is the difference between ListView and GridView in WPF?

I am trying to create a WPF database application. 我正在尝试创建一个WPF数据库应用程序。 There seems to be a few good components that I can use for showing the data in the database tables. 我可以使用一些好的组件来显示数据库表中的数据。 ListView and GridView seems to be popular for this usage. ListViewGridView似乎很受欢迎。 But for a novice, it's hard to see the difference between them. 但对于新手来说,很难看出它们之间的区别。

What is the difference between ListView and GridView ? ListViewGridView什么区别? What are the pros and cons? 优缺点都有什么?

A ListView is the object that holds the data: ListView是保存数据的对象:

ListView is an ItemsControl, which means it can contain a collection of objects of any type (such as string, image, or panel). ListView是一个ItemsControl,这意味着它可以包含任何类型的对象集合(例如字符串,图像或面板)。 For more information, see the ItemsControl class. 有关更多信息,请参阅ItemsControl类。

The presentation of the data items in a ListView is defined by its view mode, which is specified by the View property. ListView中数据项的表示由其视图模式定义,该模式由View属性指定。 Windows Presentation Foundation (WPF) provides a GridView view mode that partitions the ListView data item content into columns. Windows Presentation Foundation(WPF)提供GridView视图模式,将ListView数据项内容分区为列。 The properties and methods on GridView and its related classes style and specify the content of the columns. GridView上的属性和方法及其相关的类样式并指定列的内容。

whereas a GridView controls how that data is represented: GridView控制数据的表示方式:

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

The GridView class and its supporting classes provide the infrastructure to display data items that are specified for a ListView control in a series of columns. GridView类及其支持类提供了显示在一系列列中为ListView控件指定的数据项的基础结构。

A ListView is a WPF control, deriving from ListBox, that (in theory) can render the items using one of several view modes which are derived from ViewBase. ListView是一个WPF控件,派生自ListBox,(理论上)可以使用从ViewBase派生的几种视图模式之一来呈现项目。 GridView is the only one implemented. GridView是唯一实现的。 So in other words, it's not a choice of ListView or GridView. 换句话说,它不是ListView或GridView的选择。 If you want to display tabular data in a ListView, you would create a ListView and set its View to a GridView (which defines the column layout.) 如果要在ListView中显示表格数据,可以创建ListView并将其View设置为GridView(定义列布局)。

The reality, however, is that as far as I know, no other views were implemented. 然而,事实是,据我所知,没有其他意见得到落实。 And because ListView is not a very feature-rich control, it's largely obsolete at this point. 而且因为ListView不是一个功能非常丰富的控件,所以它在很大程度上已经过时了。 In fact, Silverlight does not even provide ListView. 实际上,Silverlight甚至不提供ListView。

There is a DataGrid control that is very close in functionality and API to the Silverlight DataGrid control and you should probably use this instead of a ListView. 有一个DataGrid控件与Silverlight DataGrid控件的功能和API非常接近,您应该使用它而不是ListView。

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

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