I'm having an issue where I have made a user control with two content collections in it. for simplicities sake we'll say its two items controls.
in the code behind I am exposing those itemCollections so that I can actually declare the content in another control.
for example
<!-- User Control xaml -->
<UserControl>
<StackPanel Orientation="Horizontal" >
<ItemsControl x:Name="_itemsControl1" />
<ItemsControl x:Name="_itemsControl2" />
</StackPanel>
</UserControl>
//in the codebehind for user control
public partial class TwoControls
{
public ItemCollection ItemsOne { get { return _itemsControl1.Items; }}
public ItemCollection ItemsTwo { get { return _itemsControl2.Items; }}
}
<!-- Using the control in xaml later -->
<Custom:TwoControls>
<Custom:TwoControls.ItemsOne>
<TextBox />
<TextBox />
<TextBox />
<TextBox />
<TextBox />
</Custom:TwoControls.ItemsOne>
<Custom:TwoControls.ItemsTwo>
<Button />
<Button />
<Button />
<Button />
<Button />
</Custom:TwoControls.ItemsTwo>
<Custom:TwoControls>
This actually works great with one small problem. As soon as I try to name any of the controls I get the following error.
<!-- Using the control in xaml later -->
<Custom:TwoControls>
<Custom:TwoControls.ItemsOne>
<TextBox x:Name="txt"/>
Cannot set Name attribute value 'txt' on element 'TextBox'. 'TextBox' is under the scope of element 'TwoControls', which already had a name registered when it was defined in another scope.
If I didn't actually have to name the controls I wouldn't. We have some tools that run expecting certain content controls to be named so as part of the build process I need them to have names. Its also worth noting that I actually have a couple of events tied up in my TwoControls class, if I were to extract that to a data template I think I could make it work but I would have to work at it a bit more than currently.
Any input on why this is would be great.