Export (0) Print
Expand All

ListView Class

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

'Declaration
<StyleTypedPropertyAttribute(Property:="ItemContainerStyle", StyleTargetType:=GetType(ListViewItem))> _
Public Class ListView
	Inherits ListBox
'Usage
Dim instance As ListView

/** @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
<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.

ListView with GridView output

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

How to: Display ListView Contents by Using a GridView

This example shows how to define a GridView view mode for a ListView control.

How to: Use Templates to Style a ListView That Uses GridView

This example shows how to use the DataTemplate and Style objects to specify the appearance of a ListView control that uses a GridView view mode.

How to: Sort a GridView Column When a Header Is Clicked

This example shows how to create a ListView control that implements a GridView view mode and sorts the data content when a user clicks a column header.

How to: Create a Custom View Mode for a ListView

This example shows how to create a custom View mode for a ListView control.

How to: Create a ListView with Editable Cells

This example shows how to create a ListView control in a GridView view mode that has editable cells.

How to: Use Triggers to Style Selected Items in a ListView

This example shows how to define Triggers for a ListViewItem control so that when a property value of a ListViewItem changes, the Style of the ListViewItem changes in response.

How to: Alternate the Background Color for Rows in a ListView

This example shows three methods that you can use to alternate the Background color for rows in a ListView.

How to: Create ListViewItems with a CheckBox

This example shows how to display a column of CheckBox controls in a ListView control that uses a GridView.

How to: Create a Style for a Dragged GridView Column Header

This example shows how to change the appearance of a dragged GridViewColumnHeader when the user changes the position of a column.

How to: Style a Row in a ListView That Implements a GridView

This example shows how to style a row in a ListView control that implements a GridViewView mode.

How to: Group Items in a ListView That Implements a GridView

This example shows how to display groups of items in the GridView view mode of a ListView control.

How to: Display Data by Using GridViewRowPresenter

This example shows how to use the GridViewRowPresenter and GridViewHeaderRowPresenter objects to display data in columns.

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

Community Additions

ADD
Show:
© 2014 Microsoft