Finds the element associated with the specified name defined within this template.
Assembly: PresentationFramework (in PresentationFramework.dll)
- Type: System::String
The string name.
Return ValueType: System::Object
The element associated with the specified name.
This example shows how to find elements that are generated by a DataTemplate.
In this example, there is a ListBox that is bound to some XML data:
If you want to retrieve the TextBlock element generated by the DataTemplate of a certain ListBoxItem, you need to get the ListBoxItem, find the ContentPresenter within that ListBoxItem, and then call on the DataTemplate that is set on that ContentPresenter. 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 DataTemplate-generated text block.
The following is the implementation of FindVisualChild, which uses the VisualTreeHelper methods:
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.