2016-02-27 59 views
0

有人可以通过移植/翻译winForms中写入的这段c#代码来帮助我移除Windows Phone 8.0吗?我真的很挣扎,我不能让它工作,我可能阅读每一个文件,我可以让我的手,但我不能让它的工作。我知道stackover流不是人们为你写代码的地方,但即时通讯无望..任何帮助赞赏我试图从文本文件和图像加载一些关于我的应用程序的信息im加载这些东西在图像和字符串数组。下面的代码:端口从WinForms到Windows Phone 8.0 C#

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); 
       } 
      } 
     } 
+0

那么,什么是不工作?它怎么不起作用?哪里出问题了?你所说的只是“我无法工作”,这是非常模糊的。你是什​​么意思? – pstrjds

+0

因为我无法将这片winForms代码放到我的Windows Phone应用程序中,所以我放弃了为Windows Phone做的事情。我没有任何样品显示我真的很抱歉.. – developer2016

回答

0

在Windows Phone上使用的相应类型(不准确的映射,当然):

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

所以翻译代码会是这样的(你需要熟悉新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(... 
+0

他们现在已将代码级别的文件夹重命名为文件夹,而不仅仅是在UI级别上? Awwwww。 –

+0

ApplicationData.Current.LocalFolder指向哪里?我得到FileNotFoundException – developer2016

+0

@MattiVirkkunen我交替使用它们 – kennyzx