c# - How to display string in list to textblock? -


i want display text text file split list textblock in ui(xaml). use databinding it's error , text don't appear have way guide me? in universal app

private async void button_click(object sender, routedeventargs e) {     string content = "00:00:00;00:00:10;hello\r\n00:00:10;00:00:20;hi";     string filename = "test.txt";     // saves string 'content' file 'filename' in app's local storage folder     byte[] filebytes = system.text.encoding.utf8.getbytes(content.tochararray());      // create file given filename in local folder; replace existing file same name     storagefile file = await windows.storage.applicationdata.current.localfolder.createfileasync(filename, creationcollisionoption.replaceexisting);      // write char array created content string file     using (var stream = await file.openstreamforwriteasync())     {         stream.write(filebytes, 0, filebytes.length);     }      storagefolder local = windows.storage.applicationdata.current.localfolder;     stream streams = await local.openstreamforreadasync(filename);      string text = "";     list<string> textread = new list<string>();     using (streamreader reader = new streamreader(streams))     {         while (text != null)         {             text = reader.readline();             if (text != null)                 textread.add(text);         }     }      foreach (string stringoutput in textread)     {         string[] words = stringoutput.split(';');          datas.add(new datum { start = words[0], end = words[1], comment = words[2] });     }      foreach (datum temp in datas)     {         string = temp.start;         string b = temp.end;         string c = temp.comment;     }  }  public class datum {     public datum data;     public string start { get; set; }     public string end { get; set; }     public string comment { get; set; } }  public class viewmodel {     public viewmodel()     {         // data         var _data = enumerable.range(1, 20)             .select(x => x => (string)(x + 'a'));                data = new observablecollection<datum>(_data);     }      public observablecollection<datum> data { get; private set; } } 

and part of xaml:

        <itemscontrol itemssource="{binding data}">                         <textblock text="{binding start}" />         </itemcontrol> 

your itemscontrol needs itemtemplate contains textblock:

<itemscontrol itemssource="{binding data}">     <itemscontrol.itemtemplate>         <datatemplate>                           <textblock text="{binding start}" />         </datatemplate>     </itemscontrol.itemtemplate> </itemscontrol> 

alternatively, can use displaymemberpath if want show string start:

  <itemscontrol itemssource="{binding data}" displaymemberpath="start" /> 

Comments