Represents a control that displays a list of data items.
Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
Visual Basic (Declaration)
<StyleTypedPropertyAttribute(Property:="ItemContainerStyle", StyleTargetType:=GetType(ListViewItem))> _
Public Class ListView
Inherits ListBox
[StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=typeof(ListViewItem))]
public class ListView : ListBox
[StyleTypedPropertyAttribute(Property=L"ItemContainerStyle", StyleTargetType=typeof(ListViewItem))]
public ref class ListView : public ListBox
/** @attribute StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=System.Windows.Controls.ListViewItem) */
public class ListView extends ListBox
StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=System.Windows.Controls.ListViewItem)
public class ListView extends ListBox
XAML Object Element Usage
<ListView>
Items
</ListView>
ContentModel: ListView is an ItemsControl and has two content properties: Items and ItemsSource. For information about how to set these properties, see the Items Control Content Model overview.
The presentation of the data items in a ListView is defined by its view mode, which is specified by the View property. Windows Presentation Foundation (WPF) provides a GridView view mode that partitions the ListView data item content into columns. The properties and methods on GridView and its related classes style and specify the content of the columns.
The following illustration shows a ListView with a GridView view.
You can also define custom views by creating a class that derives from ViewBase. For more information, see How to: Create a Custom View for a ListView.
If you define a custom ItemContainerStyle for a ListView control and also define an ItemTemplate, you must include a ContentPresenter in the ItemContainerStyle. The ContentPresenter is required for the ItemTemplate to work correctly.
To avoid alignment issues in a GridView view mode, do not add content or set properties that affect the width of an item in the ItemContainerStyle of a ListView. To prevent alignment issues, use properties and templates that are defined for the GridView view mode. This includes properties and templates that are defined for classes that are used in a GridView view mode, such as GridViewColumn and GridViewColumnHeader.
Two ListView controls cannot share the same view. To specify a view that can be used more than one time, use templates or styles. For an example of a GridView and other custom views that are defined as reusable resources, see ListView with Multiple Views Sample.
Do not use the HorizontalContentAlignment and VerticalContentAlignment properties ListView content that is displayed by using a GridView. To specify the alignment of content in a column of a GridView, define a CellTemplate.
The following example shows how to create a ListView control that implements a GridView as its View. For the complete sample, see ListView with a GridView View.
<ListView ItemsSource="{Binding Source=
{StaticResource EmployeeInfoDataSource}}">
<ListView.View>
<GridView AllowsColumnReorder="true"
ColumnHeaderToolTip="Employee Information">
<GridViewColumn DisplayMemberBinding=
"{Binding Path=FirstName}"
Header="First Name" Width="100"/>
<GridViewColumn DisplayMemberBinding=
"{Binding Path=LastName}"
Header="Last Name" Width="100"/>
<GridViewColumn DisplayMemberBinding=
"{Binding Path=EmployeeNumber}"
Header="Employee No." Width="100"/>
</GridView>
</ListView.View>
</ListView>
More Code
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
System.Windows.Controls.ItemsControl
System.Windows.Controls.Primitives.Selector
System.Windows.Controls.ListBox
System.Windows.Controls.ListView
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
.NET Framework
Supported in: 3.0