當前位置:編程學習大全網 - 網站源碼 - WPF 中的listview 怎樣綁定結構體數組?

WPF 中的listview 怎樣綁定結構體數組?

//定義數據結構

class?Student

{

public?int?Id?{?get;?set;?}

public?string?Name?{?get;?set;?}

public?DateTime?Birth?{?get;?set;?}

}//定義ListView?視圖結構

<ListView?x:Name="livStudent">

<ListView.View>

<GridView>

<GridViewColumn?Header="Id"?DisplayMemberBinding="{Binding?Path=Id}"?/>

<GridViewColumn?Header="Name"?DisplayMemberBinding="{Binding?Path=Name}"?/>

<GridViewColumn?Header="Birth"?DisplayMemberBinding="{Binding?Path=Birth}"?/>

</GridView>

</ListView.View>

</ListView>//構造數據源

var?students?=?new?Student[2];

students[0]?=?new?Student()?{?Id?=?1,?Name?=?"a",?Birth?=?new?DateTime(2015,?1,?1)?};

students[1]?=?new?Student()?{?Id?=?2,?Name?=?"b",?Birth?=?new?DateTime(2015,?2,?1)};

//綁定數據

livStudent.ItemsSource?=?students;

DisplayMemberBinding="{Binding Path=Id}"

設置綁定的屬性名稱, 註意:是屬性。

  • 上一篇:如何在linux 啟動wiki
  • 下一篇:如何編織壹個夢境空間?編織夢想空間站
  • copyright 2024編程學習大全網