Tuesday, February 24, 2009 5:56 PMI 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.
Tuesday, February 24, 2009 6:20 PMYou are trying to put two duplicate ComboBoxItems named "ItemOne" and "ItemTwo" in the StackPanel. You cannot have duplicate names.
Tuesday, February 24, 2009 6:22 PMAnd the only reason you are seeing the two ComboBoxes is because you are overriding the x:Name property from "MyComboBox" to "MyControl_X."
Tuesday, February 24, 2009 6:54 PM
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.
Tuesday, February 24, 2009 10:19 PMI think having the x:Name for normal control is okay. But there might be some problems with ComboBoxItem only. You can have x:Name for Combobox in your user control and you can use your user control multiple time.
Wednesday, February 25, 2009 12:02 AM
Thanks for the report! This is a bug with XAML namescope in this scenario. We have this on our bug list for the next release.
Thanks, Stefan Wick
Wednesday, February 25, 2009 12:51 AMWhat a terrible waste of perfectly good mspaint art. I didn't realize it was a bug -- it's just never worked for me, so I figured it wasn't allowed.