Sunday 15 June 2014

c# - Access xaml control inside ith item in flipview -



c# - Access xaml control inside ith item in flipview -

i have flipview populated code (i don't understand how modifying app).

<flipview x:name="articledetail" grid.row="1" automationproperties.automationid="itemsflipview" automationproperties.name="item details" tabindex="1" datacontext="{binding latestarticlesmodel}" itemssource="{binding items}" itemtemplate="{staticresource latestarticles1detaildetail}" selecteditem="{binding selecteditem, mode=twoway}" itemcontainerstyle="{staticresource flipitemstyle}"> </flipview> <!--data template flipview--> <datatemplate x:key="latestarticles1detaildetail"> <scrollviewer> <stackpanel> <textblock margin="0,16" text="{binding title, converter={staticresource textplainconverter}, converterparameter = 140}" style="{staticresource subheadertext}" /> <image source="{binding imageurl, converter={staticresource thumbnailconverter}, converterparameter=300}" stretch="uniformtofill" /> <textblock x:name="feedurl" margin="0,12" style="{staticresource html2xamlstyletext}" text="{binding feedurl}" visibility="collapsed"/> <richtextblock x:name="content" margin="0,12" style="{staticresource html2xamlstyle}"/> </stackpanel> </scrollviewer> </datatemplate>

from textblock named "feedurl" want extract url stored in it.

use url parse html page pointed url

after processing display content in richtextblock named "content".

the problem facing in how reference textblock , richtextblock within each item of flipview.

for getting reference items have tried 2 solutions:

i've tried code line

var mytextblock= _children.oftype<textblock>().firstordefault(c => c.name.equals("test"));

.oftype<textblock>() gives error

'system.collections.generic.list<windows.ui.xaml.controls.textblock>' not contain definition 'oftype' , no extension method 'oftype' accepting first argument of type 'system.collections.generic.list<windows.ui.xaml.controls.textblock>' found (are missing using directive or assembly reference?)

i tried solution given here, null reference.

i warning line

var item = itemscontrol.itemcontainergenerator.containerfromitem(o); windows.ui.xaml.controls.itemcontainergenerator.containerfromitem(o); obsolote.'containerform' may unavailable releases after windows phone 8.1. utilize itemscontrol.containerfromitem instead.

even if utilize itemscontrol.containerfromitem returns null reference.

please help

update:

i'm using following

if(!statusiop.statusup){ this.updatelayout(); (int = 0; < articledetail.items.count; i++) { var fvitem = this.articledetail.items[i]; var container = this.articledetail.containerfromitem(fvitem); if (container == null) { text = "null container"; } else { var tbfeedurl = findelementbyname<textblock>(container, "feedurl"); if (tbfeedurl == null) { test.text = "null text"; } else { tbfeedurl.text = tbfeedurl.text + "test"; } } }

i iterate through items in flipview, , modify info needed. using public static class

public static class statusiop { public static boolean statusup= false; }

which contains fellow member statusup. statusup serves flag when true indicates flipview info has been updated 1 time , need not updated again.

you need visualtreehelper method. code using. think can adjust needs.

first set findelementbyname method somewhere code behind file:

public t findelementbyname<t>(dependencyobject element, string schildname) t : frameworkelement { t childelement = null; var nchildcount = visualtreehelper.getchildrencount(element); (int = 0; < nchildcount; i++) { frameworkelement kid = visualtreehelper.getchild(element, i) frameworkelement; if (child == null) continue; if (child t && child.name.equals(schildname)) { childelement = (t)child; break; } childelement = findelementbyname<t>(child, schildname); if (childelement != null) break; } homecoming childelement; }

now can start using method:

this.updatelayout(); var fvitem = this.articledetail.items[articledetail.selectedindex]; var container = this.articledetail.containerfromitem(fvitem); // npe safety, deny first if (container == null) return; var tbfeedurl = findelementbyname<textblock>(container, "feedurl"); // , 1 time again deny if got null if (tbfeedurl == null) return; /* start doing stuff here. */

c# xaml windows-phone-8.1 datatemplate flipview

No comments:

Post a Comment