visual studio 2012 - How to add list items in windows phone app using c#? -


i beginner c# , windows phone programming , have code load json data message box able want display data in message box list items in page , unable understand api in msdn,help me this

programm

xaml code

<grid x:name="layoutroot" background="transparent">     <grid.rowdefinitions>         <rowdefinition height="auto"/>         <rowdefinition height="*"/>     </grid.rowdefinitions>      <!--titlepanel contains name of application , page title-->     <stackpanel x:name="titlepanel" grid.row="0" margin="12,17,0,28">         <textblock x:name="pagetitle" text="page name" margin="9,-7,12,0" style="{staticresource phonetexttitle1style}"/>     </stackpanel>      <!--contentpanel - place additional content here-->     <grid x:name="contentpanel" grid.row="1" margin="12,0,12,0">            </grid> </grid> 

cs code

 using system;     using system.collections.generic;     using system.linq;     using system.net;     using system.windows;     using system.windows.controls;     using system.windows.documents;     using system.windows.input;     using system.windows.media;     using system.windows.media.animation;     using system.windows.shapes;     using microsoft.phone.controls;     using system.runtime.serialization.json;     using system.io;     using system.text;     using system.runtime.serialization;     namespace jsonarray     {         public partial class mainpage : phoneapplicationpage         {             // constructor             public mainpage()             {                 string jsonstring = @"{         'product': [             {                 'categoryname': [                     'ashokleyland',                     'hindustanmotorsltd',                     'mahindraltd',                     'tatamotors',                     'swarajmazda'                 ],                 'categoryid': [                     '1',                     '2',                     '3',                     '4',                     '6'                 ],                 'subcategoryname': [                     'multiaxlevehicles',                     'hippohaulage',                     'hippotipper',                     'cargo',                     'pick-up'                 ],                 'subcategoryid': [                     '1',                     '2',                     '3',                     '4',                     '5'                 ],                 'typename': [                     'haulage',                     'tippers',                     'rigidtrucks',                     'cabs',                     'deliveryvan'                 ],                 'typeid': [                     '1',                     '2',                     '3',                     '4',                     '5'                 ]             }         ],         'success': 1,         'message': 'thetruckdetailsgettingsuccessfully'     }     "; ;                 rootobject totallist = new rootobject();                 rootobject childlistonly = new rootobject();                 product prdt = new product();                 memorystream ms = new memorystream(encoding.utf8.getbytes(jsonstring));                 datacontractjsonserializer ser = new datacontractjsonserializer(totallist.gettype());                 totallist = ser.readobject(ms) rootobject;                 string category = "";                 string typename = "";                 int = 0;                 int k = 0;                 foreach (var d in totallist.product)                 {                     foreach (var t in d.categoryname)                     {                         category = category + "" + t.tostring() + "\n" + "\n" + "\n";                         i++;                     }                      foreach (var t in d.typename)                     {                         typename = typename + "" + t.tostring() + "\n" + "\n" + "\n";                         k++;                     }                     foreach (var t in d.subcategoryname)                     {                         // teststring = teststring + "" + t.tostring() + "\n" + "\n" + "\n";                         i++;                     }                 }                 messagebox.show("your categorynames are:\n\n" + category);                 messagebox.show("your typenames are:\n\n" + typename);                 ms.close();               }         }         public class product         {             public list<string> categoryname { get; set; }             public list<string> categoryid { get; set; }             public list<string> subcategoryname { get; set; }             public list<string> subcategoryid { get; set; }             public list<string> typename { get; set; }             public list<string> typeid { get; set; }         }          public class rootobject         {             public list<product> product { get; set; }             public int success { get; set; }             public string message { get; set; }         }     } 

you need use longlistselector or listbox.

here tutorials

http://msdn.microsoft.com/en-us/library/windowsphone/design/hh202882%28v=vs.105%29.aspx

http://msdn.microsoft.com/en-us/library/windows/apps/hh868196.aspx

http://developer.nokia.com/community/wiki/listbox_handling_in_windows_phone

http://msdn.microsoft.com/en-us/library/windowsphone/design/jj735577%28v=vs.105%29.aspx

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj244365%28v=vs.105%29.aspx

http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/05/23/windows-phone-8-xaml-longlistselector.aspx

also, can check out series -

http://channel9.msdn.com/series/windows-phone-8-development-for-absolute-beginners

it gives overview of windows phone

edit:-

in xaml page, need add longlistselector.

a simple example-

<grid x:name="contentpanel" grid.row="1" margin="12,0,12,0"> <phone:longlistselector name="yourlist" layoutmode="list" isgroupingenabled="false">     <phone:longlistselector.itemtemplate>         <datatemplate>             <grid>               //add textblocks here             </grid>         </datatemplate>     </phone:longlistselector.itemtemplate> </phone:longlistselector> </grid> 

in code-behind -

yourlist.itemsource = yourlistobject;


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -