c# - Access other xaml controls data in another control's event -


i have below listbox binding data class(saveddataclass) defined.when user clicks on link "update" want access entire data of other members of particular instance of saveddataclass .is possible access data ? mean how access other xxaml controls data in listbox item instance when 1 of member invoked ..

        <listbox x:name="lstareadetails"  grid.row="1" margin="0,10,0,0"  >                         <listbox.itemtemplate >                             <datatemplate >                                 <stackpanel >                                      <stackpanel orientation="horizontal">                                         <textblock foreground="white" name="mydatetime" text="{binding mydatetime}"></textblock>                                     </stackpanel>                                                                             <stackpanel >                                                                                    <hyperlinkbutton content="{binding savedname}" name="lnksavedname"  click="hyperlinkbutton_click_1"   />                                         <hyperlinkbutton  content="{binding update}" name="lnkupdate" click="lnkupdate_click"/>                                     </stackpanel>                                     <textblock   text="{binding resaddress}" name="txtresaddress" textwrapping="wrap" ></textblock>                                     <textblock >otherdetails:</textblock>                                     <textblock  text="{binding area}" name="txtarea" textwrapping="wrap"></textblock>                                 </stackpanel>                             </datatemplate>                          </listbox.itemtemplate>                     </listbox>   public class saveddataclass {     public string mydatetime { get; set; }     public string savedname { get; set; }     public string update{ get; set; }     public string resaddress { get; set; }     public string area{ get; set; }     public string optionaladdressline1{ get; set; }     public string optionaladdressline2{ get; set; } } 

update link click have below event handler:

 private void lnkupdate_click(object sender, routedeventargs e)     {       //here want access other controls data e.g. mydatetime,savedname,resaddress,area,optionaladdressline1,optionaladdresline2     } 

in these situations, tag property of frameworkelement used transport underlying data object resides within datacontext you're binding to. code this:

<listbox x:name="lstareadetails" grid.row="1" margin="0,10,0,0">     <listbox.itemtemplate>         <datatemplate>             <stackpanel>                 <stackpanel orientation="horizontal">                     <textblock foreground="white" name="mydatetime" text="{binding mydatetime}"></textblock>                 </stackpanel>                                                         <stackpanel >                                                                <hyperlinkbutton content="{binding savedname}" name="lnksavedname"  click="hyperlinkbutton_click_1"   />                     <hyperlinkbutton  tag="{binding}" content="{binding update}" name="lnkupdate" click="lnkupdate_click"/>                 </stackpanel>                 <textblock   text="{binding resaddress}" name="txtresaddress" textwrapping="wrap" ></textblock>                 <textblock >otherdetails:</textblock>                 <textblock  text="{binding area}" name="txtarea" textwrapping="wrap"></textblock>             </stackpanel>         </stackpanel>     </datatemplate> </listbox.itemtemplate> 

notice on second hyperlink button, added tag attribute. code-behind this:

private void lnkupdate_click(object sender, routedeventargs e) {     var hyperlinkbutton = sender hyperlinkbutton;     if (hyperlinkbutton == null)         return;      var saveddataclass = hyperlinkbutton.tag saveddataclass;     // whatever want saved data class instance here... } 

hope helps.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -