当应用程序第一次运行时,我将一些默认值写入到 IsolatedStorageFile 中的文本文件中,如下所示:
if (!settings.Contains("firstrun"))
{
StringBuilder sb = new StringBuilder(); // Use a StringBuilder to construct output.
var store = IsolatedStorageFile.GetUserStoreForApplication(); // Create a store
store.CreateDirectory("testLocations"); // Create a directory
IsolatedStorageFileStream rootFile = store.CreateFile("locations.txt"); // Create a file in the root.
rootFile.Close(); // Close File
string[] filesInTheRoot = store.GetFileNames(); // Store all files names in an array
Debug.WriteLine(filesInTheRoot[0]); // Show first file name retrieved (only one stored at the moment)
string filePath = "locations.txt";
if (store.FileExists(filePath)) {
Debug.WriteLine("Files Exists");
StreamWriter sw =
new StreamWriter(store.OpenFile(filePath,
FileMode.Open, FileAccess.Write));
Debug.WriteLine("Writing...");
sw.WriteLine("Chicago, IL");
sw.WriteLine("Chicago, IL (Q)");
sw.WriteLine("Dulles, VA");
sw.WriteLine("Dulles, VA (Q)");
sw.WriteLine("London, UK");
sw.WriteLine("London, UK (Q)");
sw.WriteLine("San Jose, CA");
sw.WriteLine("San Jose, CA (Q)");
Debug.WriteLine("Writing complete");
}
}
这似乎可行,但现在我需要按字母顺序使用此文本文件的内容填充我的 ListPicker。
最好的方法是什么?从文本文件创建一个列表,然后用列表填充 ListPicker?