Skip to content

Suggested Addition for "How to: Find an Element by Its Name - WPF .NET Framework" #1202

@ClockEndGooner

Description

@ClockEndGooner

Type of issue

Other (describe below)

Description

The example's implementation of the Find() method will only find a child element for the specified name that has been added to the Window's or Page's Content as a non-dynamic element. By default, a dynamic UI Element (e.g., the WPF Framework UIElement was instantiated and and added to the Content of the main view programmatically and not through a XAML declaration) is not added as a NameScoped mapped object, and any calls to FindName() using a dynamic object's Name will return a null object reference.

If a FrameworkElement has been added to the Content dynamically, and you would still need to get a reference to the named element, the elements name should be registered to the NameScoped object map by calling the FrameworkElement.RegisterName() method before the element is added to the parent container for a Window or Page's Content.

See Also:
FrameworkElement.RegisterName(String, Object) Method
https://docs.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement.registername?view=windowsdesktop-5.0

Page URL

https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/how-to-find-an-element-by-its-name

Content source URL

https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/wpf/advanced/how-to-find-an-element-by-its-name.md

Document Version Independent Id

62e38876-edf9-8645-cd38-73c20cc0e16c

Article author

adegeo

Metadata

  • ID: 62e38876-edf9-8645-cd38-73c20cc0e16c
  • Service: dotnet-framework
  • Sub-service: wpf

Associated WorkItem - 498243

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredLabel to indicate an item has been imported.🗺️ mapQUESTOnly used as a way to mark an issue as updated. RepoMan should instantly remove it.Pri2Medium prioritydoc-enhancementImprove the current content [org][type][category]dotnet-framework/svcin-prwpf/subsvc

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions