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. This is a dependency property.

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

public ViewBase View { get; set; }
For XAML information, see the ViewBase type.

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. For the complete sample, see ListView That Sorts Data Sample.

ListView myListView = new ListView();

GridView myGridView = new GridView();
myGridView.AllowsColumnReorder = true; 
myGridView.ColumnHeaderToolTip = "Employee Information";

GridViewColumn gvc1 = new GridViewColumn();
gvc1.DisplayMemberBinding = new Binding("FirstName");
gvc1.Header = "FirstName";
gvc1.Width = 100;
myGridView.Columns.Add(gvc1);
GridViewColumn gvc2 = new GridViewColumn();
gvc2.DisplayMemberBinding = new Binding("LastName");
gvc2.Header = "Last Name";
gvc2.Width = 100;
myGridView.Columns.Add(gvc2);
GridViewColumn gvc3 = 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 GridView This example shows how to define a GridView view mode for a ListView control.
How to: Create a Custom View Mode for a ListView This example shows how to create a custom View mode for a ListView control.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft