Bind datetime data to Listbox in window phone 7 -


i have listbox , want bind data it. have datetime field. have saved data in datetime field eg. 01/01/2013 12.00.00. when bind data listbox display saved want display 01/01/2013.

xaml code:

   <grid x:name="contentpanel" >                 <listbox x:name="listexpense" selectionchanged="listexpense_selectionchanged">                     <listbox.itemtemplate>                         <datatemplate >                             <!--<button x:name="btndetails" width="460" height="65"  borderthickness="1" margin="0,-20,0,0" click="btndetails_click">                         <button.content>-->                             <stackpanel  orientation="vertical">                                 <stackpanel.background>                                     <lineargradientbrush endpoint="0.5,1" startpoint="0.5,0">                                         <gradientstop color="white" offset="0"/>                                     </lineargradientbrush>                                 </stackpanel.background>                                 <border  borderbrush="#120221" background="transparent" borderthickness="6" >                                     <stackpanel orientation="horizontal">                                          <textblock width="200" foreground="black" fontsize="22" margin="10,0,0,0" text="{binding categoryname}" height="30"></textblock>                                         <textblock width="70" foreground="black" fontsize="22"  margin="0,0,0,0" text="{binding price}" height="30"></textblock>                                         <textblock width="130" foreground="black" fontsize="22"  margin="25,0,50,0"  text="{binding date}" height="30"></textblock>                                      </stackpanel>                                 </border>                             </stackpanel>                             <!--</button.content>                     </button>-->                         </datatemplate>                     </listbox.itemtemplate>                 </listbox>             </grid 

xaml.cs

 var varexp = exp in empdb.expense                              join cat in empdb.category                              on exp.categoryid equals cat.categoryid                              select new { exp.expenseid, exp.date, exp.price, exp.description, cat.name };                 foreach (var item in varexp)                 {                     string[] formats = { "dd/mm/yyyy" };                     expensevo objexpense = new expensevo();                                            string strdate = item.date.tostring("dd/mm/yyyy");                                             objexpense.date = datetime.parseexact(strdate, formats, new cultureinfo("en-us"), datetimestyles.none);                      objexpense.price = item.price;                     objexpense.categoryname = item.name;                     expenselist.add(objexpense);                 } 

you can format text property:

text="{binding date, stringformat='dd/mm/yyyy'}" 

Comments

Popular posts from this blog

shader - OpenGL Shadow Map -

stringtemplate - StringTemplate4 if conditional with length -