我最近一直试图将名为KS1words.txt
的外部文本文件加载到Visual Studio 2012窗口存储空白页的列表视图中,一旦使用列表视图进入页面。该代码工作1天前,但与加载文件,我无法修复的错误,所以我创建了同样的事情,一个新的方案,并制定了相同的代码,现在不会,我已经在这里和那里连接它也是ListViews
页面的屏幕截图。你有什么想法问题的原因是什么? 我在虚拟机上运行此! 谢谢将外部文本文件加载到Visual Studio 2012的ListView中(Windows存储)
CODE:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
FillList(@"Assets\KS1words.txt");
}
async private void FillList(string filename)
{
var KS1wordlist= new List<String>();
// this method reads line separated words from a text file and populates a List object //
Windows.Storage.StorageFolder localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
// begin the file read operation
try
{
// open and read in the word list into an object called words
StorageFile sampleFile = await localFolder.GetFileAsync(filename);
var KS1wordsvar= await FileIO.ReadLinesAsync(sampleFile);
// add each word returned to a list of words declared
// globally as List wordList = new List();
foreach (var word in KS1wordsvar) { KS1wordlist.Add(word); }
List1.ItemsSource = KS1wordlist;
}
catch (Exception) {
// handle any errors with reading the file
}
请具体谈谈什么是“不工作”。你是否收到错误信息?如果该文件是在“资产”,那么你必须确保该文件(在属性选项卡)设置为“复制到输出”。这将确保文件将被复制到输出目录。 –
对不起,我的意思是,该程序运行成功,没有错误,但最终,它不显示任何东西在listview..and是文本文件不在项目中,但我将它们添加到确切的页面我试图执行它们,结果仍然相同 – Atanas
而且,是的,它被设置为始终复制到输出 – Atanas