ListView.View 属性

定义

获取或设置一个对象,用于定义如何在 ListView 控件中设置数据样式和组织数据。

public:
 property System::Windows::Controls::ViewBase ^ View { System::Windows::Controls::ViewBase ^ get(); void set(System::Windows::Controls::ViewBase ^ value); };
public System.Windows.Controls.ViewBase View { get; set; }
member this.View : System.Windows.Controls.ViewBase with get, set
Public Property View As ViewBase

属性值

ViewBase

一个 ViewBase 对象,它指定如何在 ListView中显示信息。

示例

以下示例演示如何将对象指定GridViewViewListView控件。

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);
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>

注解

.NET Framework环境包括命名GridView的可配置视图模式。 还可以创建自定义视图,该视图继承自 ViewBase。 有关详细信息,请参阅 如何:为 ListView 创建自定义视图模式

依赖项属性信息

标识符字段 ViewProperty
元数据属性设置为 true

备注

此属性 PropertyMetadata的属性元数据的类型不是 FrameworkPropertyMetadata

适用于

另请参阅