Gets or sets the identifying name of the element. The name provides a reference so that code-behind, such as event handler code, can refer to a markup element after it is constructed during processing by a XAML processor.
Assembly: PresentationFramework (in PresentationFramework.dll)
The most common usage of this property is to specify a XAML element name as an attribute in markup.
Names must be unique within a namescope. For more information, see WPF XAML Namescopes.
Getting a RegisterName to make an effective change to the property of an already loaded element.if you are creating elements in code is not common. If you have the appropriate reference in code already, you can just call methods and properties on the element reference and will not generally need the . An exception to this is if the string has some overloaded meaning, for instance if it is useful to display that name in UI. Setting a from code-behind if the original was set from markup is also not recommended, and changing the property after loading the XAML will not change the original object reference. The object references are created only when the underlying namescopes are explicitly created during parsing. You must specifically call
Setting FindName, which is available from any FrameworkElement, can find any element by in the logical tree for that element, searching the tree recursively as necessary. Or you can use the FindLogicalNode static method of LogicalTreeHelper, which also takes a string as an argument.from code has limited applications, but getting an element by is more common. One particular scenario is if your application supports a navigation model where pages reload into the application, and the run time code is not necessarily code-behind defined for that page. The utility method
Typically used root elements (Window, Page for example) implement the interface INameScope. Implementations of this interface are expected to enforce that names be unambiguous within their scope. The root elements that define this interface also define the namescope behavior boundaries for all the related APIs.
Theproperty also serves as an identifier for other processes. For instance, the WPF automation model will use as the AutomationId for clients and providers.
The string values used for x:Name Directive defined by the XAML specification. Most notably, a must start with a letter or the underscore character (_), and must contain only letters, digits, or underscores. For more information, see WPF XAML Namescopes.have some restrictions, as imposed by the underlying
IsAnimationProhibited is true in metadata), because the name itself is vital for targeting an animation. Data binding a is technically possible, but is an extremely uncommon scenario because a data-bound cannot serve the main intended purpose of the property: to provide an identifier connection point for code-behind.is one of the very few dependency properties that cannot be animated (
The following example sets the NameScope by calling RegisterName. The technique illustrated here is a requirement for animating with storyboards, because storyboards require targeting by the , and cannot be targeted by object reference.property in code, and then registers the name into the newly created
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0