我也是刚接触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. FUNCTION CALL STACK FRAME

    function call stack frame 两个寄存器 esp 栈顶指针寄存器,指向调用栈的栈顶(始终指向,意味着栈分配到哪里了,从当前栈往高地址是已经分配了的) ebp 基址指针寄存器,指向 ...

  2. react programming

    So you're curious in learning this new thing called Reactive Programming, particularly its variant c ...

  3. [Angular Tutorial] 7-XHRs & Dependency Injection

    我们受够了在应用中用硬编码的方法嵌入三部电话!现在让我们用Angular内建的叫做$http的服务来从我们的服务器获取更大的数据集吧.我们将会使用Angular的依赖注入来为PhoneListCtrl ...

  4. dotnet调用node.js写的socket服务(websocket/socket/socket.io)

    https://github.com/jstott/socketio4net/tree/develop socket.io服务端node.js,.里面有js写的客户端:http://socket.io ...

  5. IOS 微信

    原文:http://blog.csdn.net/ysy441088327/article/details/8441608 按照常例,列一些网址先: 微信开放平台首页: http://open.weix ...

  6. js原生设计模式——2面向对象编程之闭包1

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  7. java 错误 classes路径配置错误

    1. 错误显示页 2. 解决步骤 2.1. 查看 root cause 信息 org.springframework.beans.factory.BeanCreationException: Erro ...

  8. Tomcat配置全攻略

    tomcat的的下载地址http://www.apache.org/dist/jakarta/tomcat-4/ 1.安装jdk,详细操作请参考本站windows 2k和redhat 8.0下java ...

  9. Raphael的set使用

    Raphael的set使用 $(function() { initRaphael(); }); function initRaphael(e) { var paper = Raphael(0, 0, ...

  10. Spring @Transactional使用的示例

    Spring @Transactional使用的示例: 参考: http://blog.csdn.net/seng3018/article/details/6690527 http://blog.si ...