c# - WPF How to get the control in a nested template -


so i've seen lots , lots of examples has nifty data template control in , content control applying template , code behind needs grab it.

but have this:

<datatemplate x:key="fronttemplate" >     <stackpanel x:name="nowork">         <image source="images/1.png" stretch="fill" width="72" height="96" x:name="frontface"   horizontalalignment="left" verticalalignment="top"></image>     </stackpanel> </datatemplate>  <datatemplate x:key="flipitemtemplate">     <grid width="200" height="200">         <border x:name="fronthost" background="transparent">             <contentpresenter  content="{binding}" contenttemplate="{staticresource fronttemplate}" />         </border>     </grid> </datatemplate> 

you can see have data template (fronttemplate) nested inside of data template (flipitemtemplate). need access stackpanel in fronttemplate. of attempts content presenter datatemplate have failed. hoping wise sages of stackoverflow can me. how in god's name panel????

thanks!!

if xaml defined this:

<grid name="maingrid">     <grid.resources>     <datatemplate x:key="fronttemplate" >         <stackpanel x:name="nowork">             <image source="images/1.png" stretch="fill" width="72" height="96" x:name="frontface"   horizontalalignment="left" verticalalignment="top"></image>         </stackpanel>     </datatemplate>      <datatemplate x:key="flipitemtemplate">         <grid width="200" height="200">              <border x:name="fronthost" background="transparent">                 <contentpresenter name="contentpresenter"  content="{binding}" contenttemplate="{staticresource fronttemplate}" />             </border>         </grid>     </datatemplate>     </grid.resources> </grid> 

you can use:

var template = maingrid.findresource("fronttemplate") datatemplate; var stackpanel = template.loadcontent() stackpanel; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -