ListView.View Property
Gets or sets an object that defines how the data is styled and organized in a ListView control.
Assembly: PresentationFramework (in PresentationFramework.dll)
|
Identifier field |
|
|
Metadata properties set to true |
None |
Note
|
|---|
|
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.
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 SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note