Win 8 App Get text from datatemplate listview -
i'm trying learn how make datatemplate in listviews in win 8 app
i have following code in xaml code
<!-- vertical scrolling item list --> <listview x:name="itemlistview" margin="0,4.714,10,0.429" itemssource="{binding source={staticresource itemsviewsource}}" selectionchanged="itemlistview_selectionchanged" loaded="itemlistview_loaded" grid.row="4" tapped="itemlistview_tapped_1"> <listview.itemtemplate> <datatemplate> <grid height="110" margin="6"> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="*"/> </grid.columndefinitions> <border background="{staticresource listviewitemplaceholderbackgroundthemebrush}" width="110" height="110"> <image source="{binding image}" stretch="uniformtofill"/> </border> <stackpanel grid.column="1" verticalalignment="top" margin="10,0,0,0"> <textblock text="{binding title}" textwrapping="nowrap" fontfamily="global user interface"/> <textblock text="{binding subtitle}" textwrapping="nowrap"/> <textblock text="{binding description}" maxheight="60" fontfamily="global user interface"/> <textblock text="{binding description2}" maxheight="60" fontfamily="global user interface"/> <textblock text="{binding description3}" maxheight="60" fontfamily="global user interface"/> <textblock text="{binding description4}" maxheight="60" fontfamily="global user interface"/> </stackpanel> </grid> </datatemplate> </listview.itemtemplate> </listview>
this puts 6 textblocks each item on list view
problem have when select item in listview use tapped event populate details pane cant work out how 6 items selected item
can point me in right direction please
any appreciated
mark
i set tapped event grid , go through xaml path. this:
xaml:
<listview x:name="itemlistview" margin="0,4.714,10,0.429" itemssource="{binding source={staticresource itemsviewsource}}" selectionchanged="itemlistview_selectionchanged" loaded="itemlistview_loaded" grid.row="4" > <listview.itemtemplate> <datatemplate> <grid height="110" margin="6" tapped="listviewitem_tapped"> <border background="{staticresource listviewitemplaceholderbackgroundthemebrush}" width="110" height="110"> <image source="{binding image}" stretch="uniformtofill"/> </border> <stackpanel grid.column="1" verticalalignment="top" margin="10,0,0,0"> <textblock text="{binding title}" textwrapping="nowrap" fontfamily="global user interface"/> <textblock text="{binding subtitle}" textwrapping="nowrap"/> <textblock text="{binding description}" maxheight="60" fontfamily="global user interface"/> <textblock text="{binding description2}" maxheight="60" fontfamily="global user interface"/> <textblock text="{binding description3}" maxheight="60" fontfamily="global user interface"/> <textblock text="{binding description4}" maxheight="60" fontfamily="global user interface"/> </stackpanel> </grid> </datatemplate> </listview.itemtemplate> </listview>
and int code behind can this:
private async void listviewitem_tapped(object sender, tappedroutedeventargs e) { grid gridelement = (sender grid); //get stackpanel stackpanel stackpanelwithelements = gridelement.children.elementat(1) stackpanel; //get first textblock textblock titletextblock = stackpanelwithelements.children.elementat(0) textblock; //get text of textblock string title = titletextblock.text; //get next text textblock subtitletextblock = stackpanelwithelements.children.elementat(1) textblock; string subtitle = subtitletextblock.text; //get other elements ... }
Comments
Post a Comment