数据绑定过程
拥有属性的类:
可在MainPage.cs定义,也可在其他地方写,若在其他地方编写此代码,则需要在MainPage.xaml声明包含类的命名空间。比如该类写在项目名为xBindDateExample里的Models文件夹里,则在MianPage.xaml里的Page上添加 xmnls:data="using:xBindDataExample.Models" 在 DataTemplate 处添加x:DataType="data:Book"
public class Book
{
public int BookId { get; set; }
public string Title { get; set; }
public string Author { get; set; }
public string CoverImage { get; set; }
}
存储数据的类:
public class BOOkManager
{
public static List<Book> GetBooks()
{
var books = new List<Book>();
books.Add(new Book { BookId = 1, Title = "1", Author="1", CoverImage="1"});
books.Add(new Book { BookId = 2, Title = "2"