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.