Windows Phone 7: loopingarraydatasource with index values supported

Source: Internet
Author: User
Tags visual studio 2010

I have written an article: Windows Phone 7: Using arrays as the iloopingselectordatasource of loopingselector. However, my colleagues found that there was no support for the index value option when using it. Coincidentally, the main type of loopingarraydatasource used a dictionary internally, so they used this internal dictionary to add the index value attribute: selectedindex.

 

Use example to define loopingselector:

<Primitive: loopingselector xmlns: primitive = "CLR-namespace: Microsoft. Phone. Controls. primitives; Assembly = Microsoft. Phone. Controls. toolkit"

Name = "loopingselector" itemsize = "100,100"/>

 

Next, perform some tests in the loaded event of the page:

Private void page_loaded (Object sender, routedeventargs E)

{

// Set the selected element to Tony.

VaR datasource = new loopingarraydatasource (New String [] {"mgen", "Jerry", "Tony"}, 2 );

Loopingselector. datasource = datasource;

 

// Output the selecteditem and selectedindex attributes after iloopingselectordatasource. selectionchanged

Loopingselector. datasource. selectionchanged + = (SS, ee) =>

{

System. Diagnostics. Debug. writeline ("{0} {1}", datasource. selectedindex, datasource. selecteditem );

};

 

Threadpool. queueuserworkitem (_ =>

{

// Set the selected item to Jerry using selecteditem after one second

Thread. Sleep (1000 );

Dispatcher. begininvoke () => datasource. selecteditem = "Jerry ");

 

// You can use selectedindex to set the selected item to the first mgen element one second later.

Thread. Sleep (1000 );

Dispatcher. begininvoke () => datasource. selectedindex = 0 );

});

}

 

OK. The selection items of loopingselector will be set on time, and the selecteditem and selectedindex attributes will be output under Debug:

 

 

Download the source code of the current version

Note: This is an archive of Microsoft SkyDrive. Please download it directly in your browser. Some download tools may not be available for download.
Source code environment: Microsoft Visual Studio 2010 express for Windows Phone
Note: The Source Code does not contain referenced external class library files.

Related Article

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.