共用方式為


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中顯示資訊的方式。

範例

下列範例示範如何將 物件指定 GridViewView 控制項的 ListView

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

適用於

另請參閱