c# - Bind a ListBox inside an ItemsControl -


good day guys, want create list of clients , each client has group of items want's buy, shopping cart. method want use create listbox inside itemscontrol this:

        <itemscontrol name="clientlist">             <itemscontrol.itemtemplate>                 <datatemplate>                     <grid height="46">                         <grid.rowdefinitions>                             <rowdefinition height="46"/>                             <rowdefinition/>                         </grid.rowdefinitions>                         <textblock name="client" text="{binding client}" height="45" width="200" horizontalalignment="left" verticalalignment="top" margin="10,5" fontsize="26"/>                         <listbox name="itemslist" grid.row="1" itemssource="{binding items}"/>                     </grid>                 </datatemplate>                                 </itemscontrol.itemtemplate>         </itemscontrol> 

i know how populate clientlist, itemslist don't know how bind have list in code behind how going access itemslist code behind bind collection.

this code behind:

private void phoneapplicationpage_loaded(object sender, routedeventargs e)     {         //load files in isolated storage         var appstorage = isolatedstoragefile.getuserstoreforapplication();          //retrieve files         string[] clientlist = appstorage.getfilenames();          foreach (string client in clientlist)         {             //populate clients list             clients.add(new cart { client = client });              using (var file = appstorage.openfile(client, system.io.filemode.open))             {                 using (var sr = new streamreader(file))                 {                     //retrieve content of file                     string filecontent = sr.readtoend();                      //retrieve every item in file content                     int = 0;                     while (i < filecontent.length)                     {                         //format file content desired format                         string saveditems = filecontent.substring(i, 20);                         saveditems.replace("-", "  ");                           //populate items listbox                         items.add(new cart { items = saveditems });                          //move next item                         += 20;                     }                       //populate clientlist                     clientlist.itemssource = clients;                 }             }          }     } 

cart class has 2 string properties client , items. clients showing in screen items not showing. idea problem? idea problem?

you've bound itemssource="{binding items}". so, have add items property cart class.

public class cart {     public observablecollection<shoppingitem> items { get; private set; }      public client()     {          items = new observablecollection<shoppingitem>();     } } 

update

given code submitted, figured out error comes from:

private void phoneapplicationpage_loaded(object sender, routedeventargs e) {     //load files in isolated storage     var appstorage = isolatedstoragefile.getuserstoreforapplication();      //retrieve files     string[] clientlist = appstorage.getfilenames();      foreach (string client in clientlist)     {         cart cart = new cart { client = client };          //populate clients list         clients.add(cart);          using (var file = appstorage.openfile(client, system.io.filemode.open))         {             using (var sr = new streamreader(file))             {                 list<string> cartitems = new list<cartitems>();                  //retrieve content of file                 string filecontent = sr.readtoend();                  //retrieve every item in file content                 (int = 0 ; < filecontent.length ; += 20)                 {                     //format file content desired format                     string saveditems = filecontent.substring(i, 20);                     saveditems = saveditems.replace("-", "  ");  // string immutable replace not modify saveditems returns new string                      cartitems.add(saveditems);                 }                  cart.items = cartitems;             }         }          //populate clientlist         clientlist.itemssource = clients;     } } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -