Skip to content

Commit 036e040

Browse files
Copilotadegeo
andauthored
Add note about FindName behavior with dynamically added elements (#2136)
* Initial plan * Add note about dynamic element behavior with FindName Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
1 parent 3c3dcf1 commit 036e040

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

dotnet-desktop-guide/wpf/advanced/how-to-find-an-element-by-its-name.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ In this example, the method to find a particular element by its name is written
2121

2222
[!code-csharp[FEFindName#Find](~/samples/snippets/csharp/VS_Snippets_Wpf/FEFindName/CSharp/default.xaml.cs#find)]
2323
[!code-vb[FEFindName#Find](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FEFindName/VisualBasic/default.xaml.vb#find)]
24+
25+
> [!NOTE]
26+
> The <xref:System.Windows.FrameworkElement.FindName%2A> method only finds elements that are part of the XAML namescope. If you add an element to the object tree programmatically after XAML is loaded, the element's `Name` or `x:Name` value doesn't automatically register in the XAML namescope. To make a dynamically added element findable by name, call <xref:System.Windows.FrameworkElement.RegisterName%2A> on the XAML namescope (typically the page or window root) before adding the element to the parent container. For more information, see [XAML Namescopes](wpf-xaml-namescopes.md).

0 commit comments

Comments
 (0)