c# - How to identify which button is clicked in dynamically allocated buttons in Window Store App -


i developing windows 8 app. buttons dynamically populated in listview. i've created click event, how identify button selected? code wrote not working, here is

textblock lblusername = new textblock(); lblusername = (textblock)lstpeoples.findname("lblusername"); pagetitle.text = lblusername.text; 

the xaml code list view follows

<listview x:name="lstpeoples" horizontalalignment="left" height="571" margin="34,47,0,0" grid.row="1" verticalalignment="top" width="455" selectionmode="multiple" background="{staticresource comboboxitemdisabledforegroundthemebrush}" borderbrush="white">         <listview.itemtemplate>             <datatemplate>                 <grid height="80">                     <grid.columndefinitions>                         <columndefinition width="120" />                         <columndefinition width="auto"/>                     </grid.columndefinitions>                     <image x:name="imguser" height="150" source="{binding image}" />                     <stackpanel grid.column="1" horizontalalignment="left" verticalalignment="bottom">                         <textblock x:name="lblusername" text="{binding uname}" fontstyle="italic" verticalalignment="top" fontsize="18" foreground="white"  width="400"/>                     </stackpanel>                     <textblock grid.column="2" verticalalignment="top" fontsize="25" fontweight="bold" foreground="white" text="{binding name}"/>                     <button grid.column="2" horizontalalignment="center" verticalalignment="bottom" content="add friend" click="button_click"/>                 </grid>             </datatemplate>         </listview.itemtemplate>     </listview> 

seeking help.

in button click event handler, use sender object parameter locate button control , work way through visual items find textblock.

for example,

private void button_clicked(object sender, routedeventargs e) {     var button = (button)sender;     var grid = (grid)button.parent;     var lblusername = (textblock)grid.findname("lblusername");     pagetitle.text = lblusername.text; } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -