I have a collection of (thousands)data already save in my isolated storage. The problem is, after I get the collection from it and bind it to my listbox, the loading was s开发者_如何学编程o slow. What is the best way to handle this situation?
The best way to be fast is to not work with collections containing thousands of items.
Which part is slow?
If it's reading from IsolatedStorage, read less.
If you don't need all the data put it in smaller files (divide up the data) and only load the files as you need them, not all the data at once. Depending on the data and the application will affect how and if this can be done.
If it's loading large amounts of data into a ListBox, dont.
The ListBox isn't designed to hold thousands of items.
From a usability point of view it's very hard to find specific items in a very large list. Especially when you can only see a very small number of items (on screen) at once.
Consider using a LongListSelector or virtualize the list to improve performance.
I'd strongly recommend a different app design which doesn't need a long list though.
If you're actually reading the files themselves from Isolated Storage into your list, you could probably improve your performance by storing the file metadata in an XML file or in a database of some kind. For Windows Phone 7.0 you could use SterlingDB, which is an abstraction over Isolated Storage that lets you do SQL queries against data stored in the app's file system.
Creating a list with thousands of items does seem like a bad idea, but if you have an XML file with the file names and data in it, you'll probably get much better performance than if you try to loop through thousands of files and pull out the file names.
精彩评论