简体   繁体   English

从winForms移植到Windows Phone 8.0 C#

[英]Port from winForms to Windows phone 8.0 C#

can someone help me out by porting/translating this piece of c# code wrote in winForms to Windows phone 8.0 ? 有人可以通过将在winForms中编写的这段C#代码移植/翻译到Windows Phone 8.0来帮助我吗? Im really struggling with it and i cant make it work i probably read every single documentation that i could get my hands on but i just cant make it work. 我真的在努力挣扎,我无法使其正常工作,我可能会阅读每本可以使用的文档,但我只是无法使其正常工作。 I know that stackover flow is not place where people write code for you but im hopeless.. any help is appreciated Im trying to load some info about my app from a text document and image im loading those things in array of images and array of strings. 我知道不是人们为您编写代码的地方,但是我没有希望..任何帮助我都想从文本文档中加载有关我的应用程序的某些信息,并在图像数组和字符串数组中加载这些东西。 。 Here's the code : 这是代码:

private static string[] _folderPaths = Directory.GetDirectories(@"Folders");
    private string[] _imagePaths;
    private List<string> _questionsPaths = new List<string>();
    private List<string> _correctAnswersPaths = new List<string>();
    private List<string> _allAnswersPaths = new List<string>();

for (int i = 0; i < _folderPaths.Length; i++)
        {
            var _tempLocations = Directory.GetFiles(_folderPaths[i], (i + 1).ToString() + "*.txt*");
            _imagePaths = Directory.GetFiles(_folderPaths[i], "*.png", SearchOption.TopDirectoryOnly);
            foreach (string item in _tempLocations)
            {
                if (item == "Folders\\" + (i + 1).ToString() + "\\" + (i + 1).ToString() + ".txt")
                {
                    _questionsPaths.Add(item);
                }
                if (item == "Folders\\" + (i + 1).ToString() + "\\" + (i + 1).ToString() + "answer" + ".txt")
                {
                    _correctAnswersPaths.Add(item);
                }
                if (item == "Folders\\" + (i + 1).ToString() + "\\" + (i + 1).ToString() + "answers" + ".txt")
                {
                    _allAnswersPaths.Add(item);
                }
            }
        }

The corresponding types used in Windows Phones are (not precise mapping, of course): Windows Phone中使用的相应类型是(当然不是精确映射):

Directory -> StorageFolder
Directory.GetDirectories -> StorageFolder.GetFoldersAsync
Directory.GetFiles -> StorageFolder.GetFilesAsync

So the translated code would be something like this (you need to be familiar with the new await-async keywords too) 因此,翻译后的代码将是这样的(您也需要熟悉新的await-async关键字)

using Windows.Storage; 

var folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Folders"); 
var subFolders = await folder.GetFoldersAsync();
foreach (StorageFolder subFolder in subFolders)
{
    var tempFiles = await subFolder.GetFilesAsync(...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM