I created a UserControl to serve as my page, and another UserControl containing a ComboBox which I need to create multiple instances of.
<ComboBoxItem x:Name="ItemOne" Content="One"/>
<ComboBoxItem x:Name="ItemTwo" Content="Two"/>
The result is:
Error: Sys.InvalidOperationException: Runtime error 2028 in control 'Xaml1', method: The name already exists in the tree: ItemOne.
The first UserControl ComboBox works. The second UserControl ComboBox drops down to reveal an empty list.
This seems to indicate that the two instances of the ComboBox's are attempting to reference the same list of Items.
I've also encountered this problem with instances that (*should*) have been previously unloaded when I cleared the local reference.
Note: I can remedy this problem by simply eliminating the names of my ComboBoxItem's or other approaches to populating a ComboBox. I'm not looking for workarounds, just wondering if others can verify the problem or point out my error.
I'm adding two UserControls to the StackPanel. Because the ComboBox and ComboBoxItem's are contained within the UserControl, I would have expected a certain level of encapsulation.
Does Silverlight not use some form of fully qualified names?
If what you are suggesting is true, I'd have to be careful about using multiple instances of a UserControl. Furthermore, I'd have to be careful to have all my control names unique across the application...
Can you elaborate or point me to some documentation?
I never seemed to have this problem in WPF... I'm still learning the differences.