Gets or sets the identifying name of the element. The name provides an instance reference so that programmatic code-behind, such as event handler code, can refer to an element once it is constructed during parsing of XAML.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[<LocalizabilityAttribute(LocalizationCategory.NeverLocalize)>] abstract Name : string with get, set [<LocalizabilityAttribute(LocalizationCategory.NeverLocalize)>] override Name : string with get, set
Property ValueType: System.String
The name of the element.
The most common usage of this property is when specifying a XAML element name in markup.
This property essentially provides a WPF framework-level convenience property to set the XAML x:Name Directive.
Getting a from code is not common, because if you have the appropriate reference in code already, you can just call methods and properties on the element reference and do not generally need the . An exception is if the string has some overloaded meaning, for instance if it is useful to display that name in UI. Setting a from code if the original was set from markup is also not recommended, and changing the property will not change the object reference. Such object references are created only when the underlying namescopes are explicitly created during XAML loading.
You must specifically call RegisterName to make an effective change on the property of an already loaded element.
One notable case where setting from code is important is for naming elements that storyboards will run against. Before you can register a name, might also need to instantiate and assign a NameScope instance. See the Example section, or Storyboards Overview.
Setting from code has limited applications, but looking up an element by name is more common, particularly if you are employing a navigation model where pages reload into the application and the run-time code is not necessarily the code-behind of that respective page. The utility method FindName, which is available from any FrameworkContentElement, can find any element by in that element's logical tree recursively. Or you can use the FindLogicalNode static method of LogicalTreeHelper, which also takes the string as an argument.
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.