Export (0) Print
Expand All

ListView.View Property

Gets or sets an object that defines how the data is styled and organized in a ListView control.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

'Declaration
Public Property View As ViewBase

Property Value

Type: System.Windows.Controls.ViewBase
A ViewBase object that specifies how to display information in the ListView.

Identifier field

ViewProperty

Metadata properties set to true

None

NoteNote

The type of property metadata for this property is PropertyMetadata, not FrameworkPropertyMetadata.

The .NET Framework environment includes the configurable view mode named GridView. You can also create a custom view that inherits from ViewBase. For more information, see How to: Create a Custom View Mode for a ListView.

The following example shows how to specify a GridView object as the View for a ListView control.

Dim myListView As New ListView()

Dim myGridView As New GridView()
myGridView.AllowsColumnReorder = True
myGridView.ColumnHeaderToolTip = "Employee Information"

Dim gvc1 As New GridViewColumn()
gvc1.DisplayMemberBinding = New Binding("FirstName")
gvc1.Header = "FirstName"
gvc1.Width = 100
myGridView.Columns.Add(gvc1)
Dim gvc2 As New GridViewColumn()
gvc2.DisplayMemberBinding = New Binding("LastName")
gvc2.Header = "Last Name"
gvc2.Width = 100
myGridView.Columns.Add(gvc2)
Dim gvc3 As New GridViewColumn()
gvc3.DisplayMemberBinding = New Binding("EmployeeNumber")
gvc3.Header = "Employee No."
gvc3.Width = 100
myGridView.Columns.Add(gvc3)

'ItemsSource is ObservableCollection of EmployeeInfo objects
myListView.ItemsSource = New myEmployees()
myListView.View = myGridView
myStackPanel.Children.Add(myListView)
<ListView.View>

  <GridView AllowsColumnReorder="true"
            ColumnHeaderToolTip="Employee Information">

    <GridViewColumn DisplayMemberBinding=
                        "{Binding Path=FirstName}" 
                    Header="First Name" Width="100"/>

                <GridViewColumn DisplayMemberBinding=
                        "{Binding Path=LastName}" 
                    Width="100">
                    <GridViewColumnHeader>Last Name
                        <GridViewColumnHeader.ContextMenu>
                        <ContextMenu  MenuItem.Click="LastNameCM_Click"  
                                      Name="LastNameCM">
                            <MenuItem Header="Ascending" />
                            <MenuItem Header="Descending" />
                        </ContextMenu>
                        </GridViewColumnHeader.ContextMenu>
                    </GridViewColumnHeader>
                </GridViewColumn>

                <GridViewColumn DisplayMemberBinding=
                        "{Binding Path=EmployeeNumber}" 
                    Header="Employee No." Width="100"/>
  </GridView>

</ListView.View>

More Code

How to: Display ListView Contents by Using a GridViewThis example shows how to define a GridView view mode for a ListView control.
How to: Create a Custom View Mode for a ListViewThis example shows how to create a custom View mode for a ListView control.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft