Skip to main content

Microsoft Silverlight

Answered Question FindName searches across siblings!RSS Feed

(0)

chandler.chao
chandler...

Member

Member

269 points

81 Posts

FindName searches across siblings!

So I have some Xaml that looks like the following:

<StackPanel x:Name="Parent">

<StackPanel x:Name="Child1" />

<StackPanel x:Name="Child2" />

</StackPanel>

In code behind I add a child to Child2 named "grandChild".  I then try to find "grandChild" under Child1 by Child1.FindName("grandChild").  You would think it would return null but instead it is actually returning the "grandChild" that is a child of Child2!  So it seems that the FindName function is working across siblings, which of course is not what is expected.

So as a test I moved Child2 outside the Parent thereby effectively making it a sibling of "Parent".  The same FindName above now returns a null as expected.

Chandler Chao
iStreamPlanet

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: FindName searches across siblings!

Hello, this is the desired behavior. It's due to everything inside your parent StackPanel are in the same name scope.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities