I am having the same issue as sdether. As far as I can tell, I'm trying the same technique as tgrand. Here's my parent control that I want to have child objects:
public partial class TabControl : UserControl
{
public static readonly DependencyProperty TabPagesProperty = DependencyProperty.Register(
"TabPages", typeof(TabPageCollection),
typeof(TabControl),
delegate(
DependencyObject obj,
DependencyPropertyChangedEventArgs args) { });
public TabControl()
{
InitializeComponent();
}
public TabPageCollection TabPages
{
get { return GetValue(TabPagesProperty) as TabPageCollection; }
set { SetValue(TabPagesProperty, value); }
}
}
TabPageCollection is simply defined as this:
public class TabPageCollection : ObservableCollection<TabPage>
{
}
And TabPage is a simple ContentControl:
public class TabPage : ContentControl
{
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
"Header", typeof(object), typeof(TabPage),
delegate(
DependencyObject obj,
DependencyPropertyChangedEventArgs args) { });
public object Header { get; set; }
}
However, when I try to add items to the collection property, like this:
<my:TabControl>
<my:TabControl.TabPages>
<my:TabPageCollection>
<my:TabPage>
<my:TabPage.Header>
<TextBlock>Header 1</TextBlock>
</my:TabPage.Header>
<my:TabPage.Content>
<TextBlock>Content 1</TextBlock>
</my:TabPage.Content>
</my:TabPage>
<my:TabPage>
<my:TabPage.Header>
<TextBlock>Header 2</TextBlock>
</my:TabPage.Header>
<my:TabPage.Content>
<TextBlock>Content 2</TextBlock>
</my:TabPage.Content>
</my:TabPage>
</my:TabPageCollection>
</my:TabControl.TabPages>
</my:TabControl>
I get this XAML parse error:
TabPageCollection does not support TabPage as content.
tgrand, could you post your working code? According to your description, it seems like you're doing exactly what I'm trying to do.