xaml - How to Make Content Hidden in Expander Windows Phone Control -


i playing around example of expander control windows phone toolkit (i using wp7).

enter image description here

when load stripped down version seems expanded. when click on customer pizza or 2 nothing happens. sub stuff collapsed don't know how.

<phone:phoneapplicationpage      x:class="expanderviewsample.mainpage"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:phone="clr-namespace:microsoft.phone.controls;assembly=microsoft.phone"     xmlns:shell="clr-namespace:microsoft.phone.shell;assembly=microsoft.phone"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:toolkit="clr-namespace:microsoft.phone.controls;assembly=microsoft.phone.controls.toolkit"     mc:ignorable="d" d:designwidth="480" d:designheight="768"     fontfamily="{staticresource phonefontfamilynormal}"     fontsize="{staticresource phonefontsizenormal}"     foreground="{staticresource phoneforegroundbrush}"     supportedorientations="portrait" orientation="portrait"     shell:systemtray.isvisible="true">      <phone:phoneapplicationpage.resources>         <toolkit:relativetimeconverter x:key="relativetimeconverter"/>         <datatemplate x:key="customheadertemplate">             <stackpanel orientation="horizontal">                 <image source="{binding image}" stretch="none"/>                 <textblock text="{binding name}"                                      fontsize="{staticresource phonefontsizeextralarge}"                                      fontfamily="{staticresource phonefontfamilysemilight}"/>             </stackpanel>           </datatemplate>     <datatemplate x:key="customexpandertemplate">         <stackpanel orientation="horizontal">             <image source="{binding image}" stretch="none"/>             <textblock foreground="{staticresource phonesubtlebrush}" verticalalignment="center"                                         fontsize="{staticresource phonefontsizenormal}">                                 <textblock.text>                                     <binding path="dateadded" converter="{staticresource relativetimeconverter}" stringformat="date added: {0}" />                                 </textblock.text>             </textblock>         </stackpanel>     </datatemplate>     </phone:phoneapplicationpage.resources>      <!--layoutroot root grid page content placed-->     <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="applicationtitle" text="windowsphonegeek.com" style="{staticresource phonetextnormalstyle}"/>             <textblock x:name="pagetitle" text="expanderviewsample" margin="9,-7,0,0" style="{staticresource phonetexttitle2style}"/>         </stackpanel>          <!--contentpanel - place additional content here-->         <grid x:name="contentpanel" grid.row="1" margin="12,0,12,0">             <grid.rowdefinitions>                 <rowdefinition height="*" />                 <rowdefinition height="auto" />             </grid.rowdefinitions>  <listbox grid.row="0" x:name="listbox">     <listbox.itemcontainerstyle>         <style targettype="listboxitem">             <setter property="horizontalcontentalignment" value="stretch"/>         </style>     </listbox.itemcontainerstyle>     <listbox.itemspanel>         <itemspaneltemplate>             <stackpanel/>         </itemspaneltemplate>     </listbox.itemspanel>     <listbox.itemtemplate>         <datatemplate>                         <toolkit:expanderview header="{binding}" expander="{binding}"                                      isexpanded="false"                                    headertemplate="{staticresource customheadertemplate}"                                  expandertemplate="{staticresource customexpandertemplate}"></toolkit:expanderview>                     </datatemplate>     </listbox.itemtemplate> </listbox>          </grid>      </grid> </phone:phoneapplicationpage>   public partial class mainpage : phoneapplicationpage     {         // constructor         public mainpage()         {             initializecomponent();              list<custompizza> custompizzas = new list<custompizza>()             {                 new custompizza()                  {                          name = "custom pizza 1",                          isexpanded = false,                         dateadded = new datetime(2010, 7, 8),                         image="images/pizza1.png"                 },                 new custompizza() { name = "custom pizza 2", dateadded = new datetime(2011, 2, 10), image="images/pizza2.png"}              };              this.listbox.itemssource = custompizzas;              // important properties:             // isexpanded             // header             // expander             // itemssource             // headertemplate             // expandertemplate             // itemtemplate             // nonexpandableheader             // isnonexpandable             // nonexpandableheadertemplate         }       }          public class custompizza : inotifypropertychanged         {             private bool isexpanded;              public string image             {                 get;                 set;             }              public string name             {                 get;                 set;             }              public datetime dateadded             {                 get;                 set;             }               public bool isexpanded             {                                 {                     return this.isexpanded;                 }                 set                 {                     if (this.isexpanded != value)                     {                         this.isexpanded = value;                         this.onpropertychanged("isexpanded");                     }                 }             }              public event propertychangedeventhandler propertychanged;              protected void onpropertychanged(string propertyname)             {                 propertychangedeventhandler handler = this.propertychanged;                 if (handler != null)                 {                     handler(this, new propertychangedeventargs(propertyname));                 }             }         } 

i don't for

expanderview header="{binding}" expander="{binding}"  

i don't "binding" referring too. seems know data use don't know how knows.

to change expanded state of expander view can following -register tap event , add binding isexpanded (this bind isexpanded property of custompizza)

 <toolkit:expanderview header="{binding}" expander="{binding}"                                  isexpanded="{binding isexpanded}"                                headertemplate="{staticresource customheadertemplate}"                              expandertemplate="{staticresource customexpandertemplate}"                           tap="expander_ontap"></toolkit:expanderview> 

-in tap event switch isexpanded flag of custompizza:

    private void expander_ontap(object sender, system.windows.input.gestureeventargs e)     {         expanderview expander = sender expanderview;         custompizza custompizza = expander.datacontext custompizza;         custompizza.isexpanded = !custompizza.isexpanded;     } 

regarding question expanderview header="{binding}" expander="{binding}", when set (or bind) itemssource property of itemscontrol list (listbox inheriting itemscontrol), datatemplate inside itemtemplate automatically set each individual item. example here setting list of custompizza each itemtemplate datacontext custompiza. expanderview have custompizza datacontext. {binding} pass datacontext whatever inside headertemplate same datacontext (custompizza ). if had put {binding image} headertemplate have image string datacontext.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -