title: WPF: How to access Element in ListView.ItemTemplate?
body: <p>I need to access element named "PageHost" for the selected list item in the following XAML code from C# codebehind, how to do so please ?  </p>
  
  <p></p>
  
  <pre><code>        &lt;ListView.Resources&gt;
              &lt;p:PageWidthConverter x:Key="PageWidthConverter" /&gt;
          &lt;/ListView.Resources&gt;
          &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate x:Name="PagesViewDataTemplate"&gt;
                  &lt;DataTemplate.Resources&gt;
                      &lt;Style x:Key="PageHostStyle" TargetType="{x:Type p:PageHost}"&gt;
                          &lt;Setter Property="Width" Value="{Binding Path=ActualWidth, 
                                                                  Converter={StaticResource PageWidthConverter}, 
                                                                  RelativeSource={RelativeSource Mode=FindAncestor, 
                                                                  AncestorType={x:Type Grid}}}"
  
                                  /&gt;
                      &lt;/Style&gt;
                  &lt;/DataTemplate.Resources&gt;
                  &lt;p:PageHost x:Name="PageHost"&gt;
  
                  &lt;/p:PageHost&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
  
          &lt;ListView.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;WrapPanel  Orientation="Horizontal" VerticalAlignment="Top"&gt;
                      &lt;WrapPanel.LayoutTransform&gt;
                          &lt;ScaleTransform ScaleX="1" ScaleY="1"&gt;&lt;/ScaleTransform&gt;
                      &lt;/WrapPanel.LayoutTransform&gt;
                  &lt;/WrapPanel&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ListView.ItemsPanel&gt;
          &lt;ListItem&gt;
          &lt;/ListItem&gt;
  &lt;/ListView&gt;
  </code></pre>