Simple use of the ListView control load diagram list in WP8.1 development (1)

Source: Internet
Author: User

I also just contact WP programming not a few months, is in this period of time has been idle nothing, and then more like WP this system, on the study of WP this aspect of the development of language, self-study is very difficult to master this aspect of the information is not much, very early, is their own on-line to find information in the process of learning, See others share let me learn a lot, so I also want to share my experience, on the other hand also hope to communicate with you, and get everyone's guidance.

Well, don't say more, now get to the point:

ListView This control with a lot of, and the function is very powerful, before I practiced the development of two small software, I thought very simple no content, who knows in the development process, just know its function, now simply say one of the functions: Load display list picture;

First, the XAML Code on the page:

<Page x:class="Bible Story 1. BlankPage1"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using: Bible story 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> registering data to bind to-<grid.resources > <collectionviewsource x:name="Itemcollectionsource"Issourcegrouped="True"Itemspath="dirnamelist"/><!--itemspath= I've never been able to figure this out here, it's nothing.-</Grid.Resources>
<!--<ScrollViewer><ScrollViewer.Content></ScrollViewer.Content></ScrollViewer> On the ListView control between the scroll bar-<ScrollViewer> <ScrollViewer.Content> <StackPanel> <listview x:name="LV"Itemssource="{Binding Source={staticresource Itemcollectionsource}}"> <ListView.GroupStyle> <groupstyle x:name="GS"> <GroupStyle.HeaderTemplate> <datat Emplate> <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> </s Tackpanel> </DataTemplate> </groupst Yle. Headertemplate> </GroupStyle> </listview.groupstyle& Gt </ListView> </StackPanel> </ScrollViewer.Content> & Lt;/scrollviewer> </Grid></Page>

Then write a model class (which can also be written as an automatic attribute, which I am accustomed to write; M in the MVVM schema):

   Public classDirectorymodel {Private string_directoryname;  Public stringdirectoryname//property of the picture name {Get{return_directoryname;} Set{_directoryname =value;} }        Private string_directoryimagesource;  Public stringdirectoryimagesource//property of the picture path {Get{return_directoryimagesource;} Set{_directoryimagesource =value;} }    }

Build another ViewModel class (VMs in the MVVM schema):

   classDirectoryviewmodel {PrivateObservablecollection<directorymodel> _dirnamelist =NewObservablecollection<directorymodel>();  PublicObservablecollection<directorymodel>Dirnamelist {Get{return_dirnamelist;} Set{_dirnamelist=value;} }         PublicDirectoryviewmodel () {} PublicDirectoryviewmodel (observablecollection<directorymodel>List1) {             This. Dirnamelist =List1; }            }

The last is the backstage code:

  PublicBlankPage1 () { This. InitializeComponent ();
observablecollection<directorymodel> dnmlist = new observablecollection<directorymodel> ()// The Observablecollection<t> collection here is because it can change the data in real time,
and loading a lot of data can be loaded in real time, not once loaded, such as 300 pictures it may load 50, when you in the drop-down process in real time and load other pictures;
{
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); To instantiate a DVM This. Itemcollectionsource.source =DVM. dirnamelist;//binding the set properties of a DVM to a resource}

Okay, so that's it, the last one:

I am also in the study, has been practicing the MVVM framework and the ListView data binding, understanding is not very good, if there is any error or inappropriate place please correct me,

Simple use of the ListView control load diagram list in WP8.1 development (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.