c# - How to get controls inside Pivot.ItemTemplate in Pivot in UWP? -


i have following code:

 <scrollviewer x:name="swipebetweenpages" grid.row="1">                     <pivot datacontext="{staticresource viewmodel}" x:name="pivot" margin="0,-45,0,0"                                       headertemplate="{staticresource headertest}"                             itemtemplate="{staticresource pivottemplate}" itemssource="{binding articles}" selectionchanged="pivot_selectionchanged">                     </pivot>                 </scrollviewer>  <page.resources>         <viewmodels:articleviewmodel x:key="viewmodel" />         <datatemplate x:key="headertest">         </datatemplate>         <datatemplate x:key="pivottemplate">             <stackpanel margin="-15 0 -15 0">                 <grid>                     <grid.background>                         <imagebrush alignmentx="center" alignmenty="center" imagesource="assets/placeholder.jpg"></imagebrush>                     </grid.background>                     <image q42controls:imageextensions.cacheuri="{binding imageurl}" tag="{binding imageurl}" tapped="imageview"></image>                 </grid>                 <stackpanel background="white">                     <textblock x:name="headline" text="{binding headline}"                                                  margin="10 5 0 -5" textwrapping="wrap"                                                 fontsize="20" foreground="black"                                                fontfamily="{staticresource headlinecommonfamiy}"                                                pivot.slideinanimationgroup="grouptwo" height="63"                                                fontweight="bold" texttrimming="characterellipsis"/>                     <textblock text="{binding abstract}" textwrapping="wrap" fontsize="15" fontstyle="italic"                                    pivot.slideinanimationgroup="grouptwo" margin="10 5 0 10"                                            fontfamily="{staticresource abstractcommonfamily}"/>                                    </stackpanel>                 <stackpanel x:name="descriptionsp" background="white">                 <richtextblock istextselectionenabled="false" x:name="richtextblock"                                 local:properties.html="{binding articledetail}" textwrapping="wrap"                                pivot.slideinanimationgroup="grouptwo" margin="10 5 0 10"                                        fontfamily="{staticresource contentcontrolthemefontfamily}">                 </richtextblock>             </stackpanel>             </stackpanel>         </datatemplate>     </page.resources> 

how richtextblock control inside stackpanel?

now, trying following code in c# end:

private t findelementinvisualtree<t>(dependencyobject parentelement) t : dependencyobject         {             var count = visualtreehelper.getchildrencount(parentelement);             if (count == 0) return null;              (int = 0; < count; i++)             {                 var child = visualtreehelper.getchild(parentelement, i);                 if (child != null && child t)                     return (t)child;                 else                 {                     var result = findelementinvisualtree<t>(child);                     if (result != null)                         return result;                 }             }             return null;         }  richtextblock richtextblock = new richtextblock();             stackpanel rootstackpanel = new stackpanel();             stackpanel childstackpanel = new stackpanel();      pivotitem item = (sender pivot).containerfromitem((sender pivot).selecteditem) pivotitem;             rootstackpanel = item.contenttemplate.loadcontent() stackpanel;             childstackpanel = rootstackpanel.findname("descriptionsp") stackpanel;             richtextblock = rootstackpanel.findname("richtextblock") richtextblock;   paragraph paragraph = new paragraph();             run run = new run();              // customize properties on richtextblock.             richtextblock.istextselectionenabled = true;             richtextblock.selectionhighlightcolor = new solidcolorbrush(windows.ui.colors.pink);             richtextblock.foreground = new solidcolorbrush(windows.ui.colors.blue);             richtextblock.fontweight = windows.ui.text.fontweights.light;             richtextblock.fontfamily = new fontfamily("arial");             richtextblock.fontstyle = windows.ui.text.fontstyle.italic;             richtextblock.fontsize = 50;             //run.text = "this sample text demonstrate properties.";              //add run paragraph, paragraph richtextblock.             paragraph.inlines.add(run);             richtextblock.blocks.add(paragraph);              // add richtextblock visual tree (assumes stackpanel decalred in xaml).             //childstackpanel.children.add(richtextblock);             //rootstackpanel.children.add(richtextblock); 

but not able control richtextblock. getting null value. please me. thanks.

you can use contenttemplate of pivotitem template of pivotitem example this:

pivotitem item = (sender pivot).containerfromitem((sender pivot).selecteditem) pivotitem; var rootstackpanel = item.contenttemplate.loadcontent() stackpanel; var richtb = rootstackpanel.findname("richtb") richtextblock; 

and firstly gave name richtextblock "richtb".


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -