我也是刚接触WP编程没几个月,就是在这段时间一直闲着没事,然后又比较喜欢WP这款系统,就学习了WP这方面的开发言语,自学是很困难的,掌握这方面的资料不多,很初级,就是自己在网上找资料学习过程中,看到别人的分享让我学到了很多,所以我也想分享一下自己的经验,另一方面也希望和大家交流交流,并得到大家的指点。

好了,不多说了,现在开始进入正题吧:

ListView这个控件用的很多,而且功能很强大,在我练习开发两个小软件的之前,我以为很简单没什么内容,谁知在开发过程中,才知道它的功能之多,现在就简单说其中的一个功能:加载显示列表图片;

先上Page上的 XAML代码:

<Page
x:Class="圣经故事1.BlankPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:圣经故事1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <!--<Grid.Resources></Grid.Resources>之间注册要绑定的数据-->
<Grid.Resources>
<CollectionViewSource x:Name="itemcollectionSource" IsSourceGrouped="True" ItemsPath="DirNameList"/><!--ItemsPath=我一直没怎么搞懂,在这里这个可不要,没什么用-->
</Grid.Resources>
<!--<ScrollViewer><ScrollViewer.Content></ScrollViewer.Content></ScrollViewer>在之间的ListView控件上加滚动条-->
<ScrollViewer>
<ScrollViewer.Content> <StackPanel>
<ListView x:Name="lv" ItemsSource="{Binding Source={StaticResource itemcollectionSource}}">
<ListView.GroupStyle>
<GroupStyle x:Name="gs">
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="im1" Source="{Binding Path=DirectoryImageSource}" Height="" Width="" Stretch="Uniform"/>
<StackPanel>
<TextBlock x:Name="te1" Text="{Binding Path=DirectoryName}" />
</StackPanel>
</StackPanel> </DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</StackPanel> </ScrollViewer.Content>
</ScrollViewer> </Grid>
</Page>

然后再写一个Model类(当然也可以写成自动属性,我习惯这样写;MVVM架构中的M):

  public class DirectoryModel
{
private string _directoryName;
public string DirectoryName//图片名称的属性
{
get { return _directoryName; }
set { _directoryName = value; }
} private string _directoryImageSource;
public string DirectoryImageSource//图片路径的属性
{
get { return _directoryImageSource; }
set { _directoryImageSource = value; }
}
}

再建一个ViewModel类(MVVM架构中的VM):

   class DirectoryViewModel
{ private ObservableCollection<DirectoryModel> _dirNameList = new ObservableCollection<DirectoryModel>();
public ObservableCollection<DirectoryModel> DirNameList
{
get { return _dirNameList; }
set { _dirNameList=value; }
}
public DirectoryViewModel()
{ }
public DirectoryViewModel( ObservableCollection<DirectoryModel> list1)
{
this.DirNameList = list1;
} }

最后是后台代码了:

 public BlankPage1()
{
this.InitializeComponent();

 ObservableCollection<DirectoryModel> dnmList = new ObservableCollection<DirectoryModel>()//这里用ObservableCollection<T>集合,是因为它能实时更改数据,
//且在加载大量数据时能实时加载,不是一次加载完,比如300张图片它可能加载50张,当你在下拉过程中实时更并加载其它的图片;
        {
            new DirectoryModel() { DirectoryImageSource="Assets/DirectoryImages/1.jpg", DirectoryName="asdfaf"},
            new DirectoryModel() { DirectoryImageSource="Assets/DirectoryImages/2.jpg", DirectoryName="fffffffffffff" },
            new DirectoryModel() { DirectoryImageSource="Assets/DirectoryImages/3.jpg", DirectoryName="aaaaaaaaaasfsaf" },
            new DirectoryModel() { DirectoryImageSource="Assets/DirectoryImages/4.jpg", DirectoryName="aaaaaaaaaasfsaf" },
        }; DirectoryViewModel dvm= new DirectoryViewModel(dnmList); //对dvm进行实例化
this.itemcollectionSource.Source =dvm.DirNameList;//将dvm的集合属性绑定到资源当中
}

好了,这样就完成了,上一张效果图:

我现在也在学习当中,一直在练习MVVM架构及LISTVIEW这方面数据绑定,理解不是太好,如果有哪错误或不合适的地方请各位指正,

WP8.1开发中ListView控件加载图列表的简单使用(1)的更多相关文章

  1. delphi 中 image 控件加载bmp、JPG、GIF、PNG等图片的办法

    procedure TForm1.Button1Click(Sender: TObject);var  jpg: TJPEGImage; // 要use Jpeg单元begin  // 显示jpg大图 ...

  2. [转]Delphi 中 image 控件加载bmp、JPG、GIF、PNG等图片的办法

    procedure TForm1.Button1Click(Sender: TObject); var jpg: TJPEGImage; // 要use Jpeg单元 begin // 显示jpg大图 ...

  3. Android中ListView控件的使用

    Android中ListView控件的使用 ListView展示数据的原理 在Android中,其实ListView就相当于web中的jsp,Adapter是适配器,它就相当于web中的Servlet ...

  4. android中ListView控件&&onItemClick事件中获取listView传递的数据

    http://blog.csdn.net/aben_2005/article/details/6592205 本文转载自:android中ListView控件&&onItemClick ...

  5. C# winform项目中ListView控件使用CheckBoxes属性实现单选功能

    C# winform项目中ListView控件使用CheckBoxes属性实现单选功能 在做项目时需要使用ListView控件的CheckBoxes属性显示,还要在点击行时自动选中CheckBoxes ...

  6. C#窗体加载和控件加载不同步导致控件闪烁

    窗体加载和控件加载不同步导致的控件闪烁现象:// 代码块加在父窗体中的任意位置,解决窗体加载和控件加载不同步导致的控件闪烁问题        protected override CreatePara ...

  7. 关于4A网络安全管控平台控件加载失败的解决方法

    最近电脑重装系统后,到公司登录4A管控平台提示"控件加载失败","无效的参数为:Null","点击资源无任何反映"等等问题 别人的电脑用的好 ...

  8. paip.gui控件tabs控件加载内容的原理以及easyui最佳实现

    paip.gui控件tabs控件加载内容的原理以及easyui最佳实现 //////////////tabs控件的加载 同form窗体一样,俩个方式 两个方式:一个是url,简单的文本可以使用这个,不 ...

  9. C#拖曳控件加载,bll报错问题

    C#拖曳控件加载,bll报错问题,加载时实例如化bll时加上一个判断 if (!(GetService(typeof(IDesignerHost)) != null            || Sys ...

随机推荐

  1. 转:HTTPS 升级指南

    上一篇文章我介绍了 HTTP/2 协议 ,它只有在 HTTPS 环境才会生效. 为了升级到 HTTP/2 协议,必须先启用 HTTPS.如果你不了解 HTTPS 协议(学名 TLS 协议),可以参考我 ...

  2. php管理关系工具Composer 之安装与下载

    参考网址:http://www.phpcomposer.com https://packagist.org 1.linux 安装Composer curl -sS https://getcompose ...

  3. 微信小程序之----video视频播放

    vidao 我现在看到的官方文档是不带danmu(弹幕)属性的,之前是有的,不过现在这个属性还可以生效.控制视频的状态可以根据video标签的唯一id得到一个对象实例.video组件并不具备actio ...

  4. UVa 10176 - Ocean Deep ! - Make it shallow !!

    题目大意:判断一个很大的二进制能否被131071整除.在二进制转十进制的过程中不断取模,最后判断结果是否是0就可以了. #include <cstdio> #include <cst ...

  5. DataTabel DataSet 对象 转换成json

    public class DataTableConvertJson    { #region dataTable转换成Json格式        /// <summary>         ...

  6. Windows 7 Professional安装多语言包

    本文出自 "王春海的博客" 博客,请务必保留此出处http://wangchunhai.blog.51cto.com/225186/223635 下载了Windows 7 Prof ...

  7. checkbox、radio控件和文字不对其

    一般使用html控件的时候  单选按钮和复选框的控件和文字不对齐 给input控件加上   style="vertical-align: middle; margin-top: -2px; ...

  8. 解压文件--linux

    linux下不同的文件格式用不同的命令解压. 对于tar.gz文件,用以下命令. .tar.gz 和 .tgz解压:tar zxvf FileName.tar.gz压缩:tar zcvf FileNa ...

  9. YII 1.0 缓存使用

    在main.php的组件components中配置设置添加缓存 'cache'=>array( 'class' => 'system.caching.CFileCache' ), 也就是f ...

  10. iOS 之 ARC 的内存泄露

    循环引用导致内存泄露,如block容易内存泄露