c# - How to change the visibility of a template button in a listbox? -


i creating windows phone application , have problem listbox template. hide "morebutton" defined in morelistboxstyle @ runtime. tried create property , bind visibility property of button doesn't work.

how should ?

<phone:phoneapplicationpage.resources>     <style x:key="morelistboxstyle" targettype="listbox">         <setter property="background" value="transparent"/>         <setter property="foreground" value="{staticresource phoneforegroundbrush}"/>         <setter property="scrollviewer.horizontalscrollbarvisibility" value="disabled"/>         <setter property="scrollviewer.verticalscrollbarvisibility" value="auto"/>         <setter property="borderthickness" value="0"/>         <setter property="borderbrush" value="transparent"/>         <setter property="padding" value="0"/>         <setter property="template">             <setter.value>                 <controltemplate targettype="listbox">                     <scrollviewer x:name="scrollviewer" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" foreground="{templatebinding foreground}" padding="{templatebinding padding}">                         <stackpanel >                             <itemspresenter  />                             <button x:name="morebutton"   content="{binding path=localeresources.more, source={staticresource localizedstrings}}" height="67" margin="0,0,8,0" borderbrush="{x:null}" foreground="{staticresource phoneforegroundbrush}" borderthickness="0" fontsize="17" fontweight="bold" click="morebutton_click"  />                         </stackpanel>                     </scrollviewer>                 </controltemplate>             </setter.value>         </setter>     </style> </phone:phoneapplicationpage.resources> 

and listbox :

<listbox x:name="randomlistbox" itemssource="{binding}" grid.row="1" style="{staticresource morelistboxstyle}">                     <listbox.itemtemplate>                         <datatemplate>                             <stackpanel orientation="vertical">                                 <textblock text="{binding mytext}" textwrapping="wrap" width="440" margin="0,10"   name="{binding myid}" manipulationcompleted="textblock_manipulationcompleted" />                                 <textblock text="{binding name}" width="440" textwrapping="wrap" textalignment="right" margin="0,0,0,15" />                                 <rectangle width="440" height="3" fill="{staticresource phoneforegroundbrush}"></rectangle>                             </stackpanel>                         </datatemplate>                     </listbox.itemtemplate>                  </listbox>  

as far understand question think have 2 options:

if using clr property make sure have implemented inotifypropertychanged example:

public partial class mainpage : phoneapplicationpage, inotifypropertychanged {        ...     visibility sampleproperty;     public visibility sampleproperty     {                 {             return sampleproperty;         }         set         {             sampleproperty = value;             // call onpropertychanged whenever property updated             onpropertychanged("sampleproperty");         }      }      public event propertychangedeventhandler propertychanged;     protected void onpropertychanged(string name)     {         propertychangedeventhandler handler = propertychanged;         if (handler != null)         {             handler(this, new propertychangedeventargs(name));         }   } } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -