c# - How to access xaml Control inside DataTemplate inside FlipView -


i want access "image" element in c# code. know cannot access directly since in datatemplate. have tried visual trees still not able "image" control element in code .

<flipview             x:name="flipview"             automationproperties.automationid="itemsflipview"             automationproperties.name="item details"             tabindex="1"             grid.rowspan="2"             itemssource="{binding source={staticresource itemsviewsource}}" selectionchanged="flipview_selectionchanged">              <flipview.itemcontainerstyle>                 <style targettype="flipviewitem">                     <setter property="margin" value="0,137,0,0"/>                 </style>             </flipview.itemcontainerstyle>              <flipview.itemtemplate>                 <datatemplate>                      <!--                         usercontrol chosen templated item because supports visual state management                         loaded/unloaded events explicitly subscribe view state updates page                     -->                     <usercontrol loaded="startlayoutupdates" unloaded="stoplayoutupdates">                         <scrollviewer x:name="scrollviewer" style="{staticresource horizontalscrollviewerstyle}" grid.row="1">                              <!-- content allowed flow across many columns needed -->                             <common:richtextcolumns x:name="richtextcolumns" margin="117,0,117,47">                                 <richtextblock x:name="richtextblock" width="560" style="{staticresource itemrichtextstyle}" istextselectionenabled="false">                                     <paragraph>                                         <run fontsize="26.667" fontweight="light" text="{binding title}"/>                                         <linebreak/>                                         <linebreak/>                                         <run fontweight="normal" text="{binding subtitle}"/>                                     </paragraph>                                     <paragraph linestackingstrategy="maxheight">                                         <inlineuicontainer>                                             <image x:name="image" maxheight="480" margin="0,20,0,10" stretch="uniform" source="{binding image}" automationproperties.name="{binding title}"/>                                         </inlineuicontainer>                                     </paragraph>                                                                   </richtextblock>                             </common:richtextcolumns>                         </scrollviewer>                     </usercontrol>                 </datatemplate>             </flipview.itemtemplate> </flipview> 

i have tried , able access control inside of flipview datatemplate described. try below approach , let me know if helps.

public static ienumerable<t> recursechildren<t>(dependencyobject root) t : uielement {     if (root t)     {         yield return root t;     }      if (root != null)     {         var count = visualtreehelper.getchildrencount(root);           (var idx = 0; idx < count; idx++)         {             foreach (var child in recursechildren<t>(visualtreehelper.getchild(root, idx)))             {                 yield return child;             }         }     } } 

accessing image control:

var imagecontrol = recursechildren<image>(rootvisual).firstordefault(); 

here rootvisual grid instance in page.


Comments