Say the following HierarchicalDataTemplate displays 2 Data Sets. Then there a 2 ListBoxes with the same x:Name ="MyListBoxName". How does WPF knows which one to pass as CommandParameter ????
<HierarchicalDataTemplate ItemsSource="{Binding SubNodes}">
<ListBox x:Name="MyListBoxName">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}, Path=DataContext.SelectedCommand}" CommandParameter="{Binding ElementName=MyListBoxName}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</HierarchicalDataTemplate>
Thanks :)
WPF uses something similar to a bubbling event when resolving the name.
Since it finds an element with the name
MyListBoxNamewithin its immediate parent template it will use that one.If not it will try to find it in the parent template's parent template and so on.
This is why in your case it compiles and works perfectly but fails if you try to add duplicated name within the same template