Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug FindName searches across siblings!
1 replies. Latest Post by Yi-Lun Luo - MSFT on March 27, 2008.
(0)
chandler...
Member
269 points
81 Posts
03-25-2008 7:44 PM |
So I have some Xaml that looks like the following:
<StackPanel x:Name="Parent">
<StackPanel x:Name="Child1" /> <StackPanel x:Name="Child2" />
<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.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-27-2008 6:01 AM |
Hello, this is the desired behavior. It's due to everything inside your parent StackPanel are in the same name scope.