Click events in Windows Phone ListBox

Source: Internet
Author: User

Tags: Technology share stack img Container Select font = = Tag txt

Front desk

<listbox x:name= "ListBox1" margin= "6" ><listbox.itemtemplate><datatemplate><grid Margin= "15" Tag= "{Binding ImageID}" tap= "Post_click" ><stackpanel orientation= "horizontal" ><image source= "{Binding Image} "width=" height= "stretch=" Fill "/><textblock text=" {Binding ImageName} "fontsize=" 30 " textwrapping= "Wrap" width= "/></stackpanel></grid></datatemplate></" Listbox.itemtemplate></listbox>


Private T findfirstelementinvisualtree<t> (DependencyObject parentelement) where t:dependencyobject{var count =  Visualtreehelper.getchildrencount (parentelement); if (count = = 0) return null;for (int i = 0; i < count; i++) {var child = Visualtreehelper.getchild (parentelement, I); if (child! = NULL && child was T) {return (T) child;} Else{var result = findfirstelementinvisualtree<t> (child), if (result! = null) return result;}} return null;}

Need to bind

private void Post_click (object sender, System.Windows.Input.GestureEventArgs e) {var selectedindex = ListBox1. SelectedIndex; ListBoxItem item = ListBox1. Itemcontainergenerator.containerfromindex (SelectedIndex) as ListBoxItem; StackPanel border = findfirstelementinvisualtree<stackpanel> (item); Image img = Findfirstelementinvisualtree <Image> (item); TextBlock Txtblock = findfirstelementinvisualtree<textblock> (item); MessageBox.Show (TxtBlock.Text.ToString ());}

Click events in Windows Phone ListBox

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: