--- title: "How to: Find DataTemplate-Generated Elements" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "finding DataTemplate elements [WPF]" - "DataTemplate [WPF]" ms.assetid: bfcd564e-5e9e-451e-8641-a9b5c3cfac90 --- # How to: Find DataTemplate-Generated Elements This example shows how to find elements that are generated by a . ## Example In this example, there is a that is bound to some XML data: [!code-xaml[FindGeneratedItems#LB](~/samples/snippets/csharp/VS_Snippets_Wpf/FindGeneratedItems/CSharp/Window1.xaml#lb)] The uses the following : [!code-xaml[FindGeneratedItems#DT](~/samples/snippets/csharp/VS_Snippets_Wpf/FindGeneratedItems/CSharp/Window1.xaml#dt)] If you want to retrieve the element generated by the of a certain , you need to get the , find the within that , and then call on the that is set on that . The following example shows how to perform those steps. For demonstration purposes, this example creates a message box that shows the text content of the -generated text block. [!code-csharp[FindGeneratedItems#DTFindElement](~/samples/snippets/csharp/VS_Snippets_Wpf/FindGeneratedItems/CSharp/Window1.xaml.cs#dtfindelement)] [!code-vb[FindGeneratedItems#DTFindElement](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FindGeneratedItems/VisualBasic/Window1.xaml.vb#dtfindelement)] The following is the implementation of `FindVisualChild`, which uses the methods: [!code-csharp[FindGeneratedItems#FVC](~/samples/snippets/csharp/VS_Snippets_Wpf/FindGeneratedItems/CSharp/Window1.xaml.cs#fvc)] [!code-vb[FindGeneratedItems#FVC](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FindGeneratedItems/VisualBasic/Window1.xaml.vb#fvc)] ## See also - [How to: Find ControlTemplate-Generated Elements](../controls/how-to-find-controltemplate-generated-elements.md) - [Data Binding Overview](data-binding-overview.md) - [How-to Topics](data-binding-how-to-topics.md) - [Styling and Templating](../controls/styles-templates-overview.md) - [WPF XAML Namescopes](../advanced/wpf-xaml-namescopes.md) - [Trees in WPF](../advanced/trees-in-wpf.md)