Export (0) Print
Expand All

FrameworkElement.FindName Method

Finds an element that has the provided identifier name.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

'Declaration
Public Function FindName ( _
	name As String _
) As Object

Parameters

name
Type: System.String

The name of the requested element.

Return Value

Type: System.Object
The requested element. This can be Nothing if no matching element was found.

If the element has child elements, these child elements are all searched recursively for the requested named element.

FindName operates within the current element's namescope. For details, see WPF XAML Namescopes.

This example describes how to use the FindName method to find an element by its Name value.

In this example, the method to find a particular element by its name is written as the event handler of a button. stackPanel is the Name of the root FrameworkElement being searched, and the example method then visually indicates the found element by casting it as TextBlock and changing one of the TextBlock visible UI properties.

		Private Sub Find(ByVal sender As Object, ByVal e As RoutedEventArgs)
			Dim wantedNode As Object = stackPanel.FindName("dog")
			If TypeOf wantedNode Is TextBlock Then
				' Following executed if Text element was found.
				Dim wantedChild As TextBlock = TryCast(wantedNode, TextBlock)
				wantedChild.Foreground = Brushes.Blue
			End If
		End Sub

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, 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.

Show:
© 2014 Microsoft