Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkElement.RegisterName Method

Provides an accessor that simplifies access to the NameScope registration method.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
'Declaration
Public Sub RegisterName ( _
	name As String, _
	scopedElement As Object _
)

Parameters

name
Type: System.String

Name to use for the specified name-object mapping.

scopedElement
Type: System.Object

Object for the mapping.

This method is a convenience method for calling RegisterName. The implementation will check successive parent elements until it finds the applicable NameScope implementation, which is found by finding an element that implements INameScope. For more information about namescopes, see WPF XAML Namescopes.

Calling RegisterName is necessary in order to correctly hook up animation storyboards for applications when created in code. This is because one of the key storyboard properties, TargetName, uses a run-time name lookup instead of being able to take a reference to a target element. This is true even if that element is accessible by reference from the code. For more information on why you need to register names for storyboard targets, see Storyboards Overview.


Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes

Namespace Microsoft.Samples.Animation.AnimatingWithStoryboards




	Public Class ScopeExample
		Inherits Page

		Private myStoryboard As Storyboard
		Private myMainPanel As StackPanel
		Private button1, button2 As Button

		Public Sub New()

			Me.Background = Brushes.White
			myMainPanel = New StackPanel()

			' Create a name scope for the stackpanel. 
			NameScope.SetNameScope(myMainPanel, New NameScope())

			myMainPanel.Background = Brushes.Orange

			button1 = New Button()
			button1.Name = "Button1"

			' Register button1's name with myMainPanel.
			myMainPanel.RegisterName(button1.Name, button1)
			button1.Content = "Button 1"
			AddHandler button1.Click, AddressOf button1Clicked
			myMainPanel.Children.Add(button1)

			button2 = New Button()
			button2.Name = "Button2"

			' Register button2's name with myMainPanel.
			myMainPanel.RegisterName(button2.Name, button2)
			button2.Content = "Button 2"
			AddHandler button2.Click, AddressOf button2Clicked
			myMainPanel.Children.Add(button2)


			' Create some animations and a storyboard.
			Dim button1WidthAnimation As New DoubleAnimation(300, 200, New Duration(TimeSpan.FromSeconds(5)))
			Storyboard.SetTargetName(button1WidthAnimation, button1.Name)
			Storyboard.SetTargetProperty(button1WidthAnimation, New PropertyPath(Button.WidthProperty))

			Dim button2WidthAnimation As New DoubleAnimation(300, 200, New Duration(TimeSpan.FromSeconds(5)))
			Storyboard.SetTargetName(button2WidthAnimation, button2.Name)
			Storyboard.SetTargetProperty(button2WidthAnimation, New PropertyPath(Button.WidthProperty))

			Dim heightAnimationWithoutTarget As New DoubleAnimation(300, 200, New Duration(TimeSpan.FromSeconds(5)))
			Storyboard.SetTargetProperty(heightAnimationWithoutTarget, New PropertyPath(FrameworkElement.HeightProperty))

			myStoryboard = New Storyboard()
			myStoryboard.Children.Add(button1WidthAnimation)
			myStoryboard.Children.Add(button2WidthAnimation)
			myStoryboard.Children.Add(heightAnimationWithoutTarget)

			Me.Content = myMainPanel

		End Sub


		Private Sub button1Clicked(ByVal sender As Object, ByVal args As RoutedEventArgs)

			' Starts the animations. The animation without a specified 
			' target name, heightAnimationWithoutTarget, is applied to
			' myMainPanel.
			myStoryboard.Begin(myMainPanel)

		End Sub

		Private Sub button2Clicked(ByVal sender As Object, ByVal args As RoutedEventArgs)

			' Starts the animations. The animation without a specified 
			' target name, heightAnimationWithoutTarget, is applied to
			' button2.
			myStoryboard.Begin(button2)

		End Sub

	End Class


End Namespace

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, 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. All rights reserved.