网上查到关于GridView的资料大多是如何显示分组数据的,最基本的用法介绍的比较少,这里介绍一下如何使用GridView显示最简单的数据,仅供入门者参考。
添加新项,选择项页。
点是添加文件。
在ItemsPage1.xaml中可以看到<DataTemplate>有三个控件,是一个Image和两个TextBlock,分别绑定的字段为ImagePath,Title和Subtitle。在ItemsPage1.xaml.cs中添加如下新类:
class clsItemSource{ public string ImagePath { get; set; } public string Title { get; set; } public string Subtitle { get; set; } public clsItemSource(string ImagePath, string Title, string Subtitle) { this.ImagePath = ImagePath; this.Title = Title; this.Subtitle = Subtitle; }}
在navigationHelper_LoadState中添加
ObservableCollection<clsItemSource> lstItemSource = new ObservableCollection<clsItemSource>();itemGridView.ItemsSource = lstItemSource;lstItemSource.Add(new clsItemSource("/Asseta/Logo.scale-100.png", "title1", "subtitle1"));lstItemSource.Add(new clsItemSource("/Asseta/Logo.scale-100.png", "title2", "subtitle2"));
然后在MainPage中添加一个按钮,并导航到该页面
Frame.Navigate(typeof(ItemsPage1));
运行即可。
本文仅介绍了最基本的用法,需使用更复杂的功能可搜索相关资料。
转载于:https://www.cnblogs.com/lzn1007/p/4120134.html
相关资源:各显卡算力对照表!