我创建了两个自定义控件。1. LeafControl 2- LeafItemControl。在 LeafControl 中,我创建了一个“列表”类型的依赖属性作为“项目”。
同样在 LeafItemControl 中,我公开了另一个依赖属性,称为 ContentControl 类型的“ItemDetails”。
<!---Base Custom Control "LeafControl"-->
<uc:LeafControlItem.ItemDetails> <!--"ItemDetails" is a Dependency Property of type "LeafControl" in "LeafControlItem" custom control --> <uc:LeafControl> <!--Nested Control of same type ???--> <uc:LeafControl.Items> <uc:LeafControlItem Level="Some Type"> <uc:LeafControlItem.ItemContent> <GroupBox BorderThickness="0"> <StackPanel Orientation="Horizontal"> <TextBox Text="Property"></TextBox> </StackPanel> </GroupBox> </uc:LeafControlItem.ItemContent> </uc:LeafControlItem> <uc:LeafControlItem Level="Variable"> <uc:LeafControlItem.ItemContent> <GroupBox BorderThickness="0"> <StackPanel Orientation="Horizontal"> <TextBox Text="Ellipse2.Top"></TextBox> </StackPanel> </GroupBox> </uc:LeafControlItem.ItemContent> </uc:LeafControlItem> </uc:LeafControl.Items> </uc:LeafControl> </uc:LeafControlItem.ItemDetails> </uc:LeafControlItem>
当我尝试访问基本自定义控件中的“项目”时。所有子自定义控件都被添加为什么?我应该怎么做才能使每个自定义控件对象(基础和子对象)都有单独的“项目”。
我在基本自定义控件中使用了依赖属性,如下所示:
#region LeafControlItemCollection
public List<LeafControlItem> Items
{
get { return (List<LeafControlItem>)GetValue(ItemsProperty); }
set { SetValue(ItemsProperty, value); }
}
public static readonly DependencyProperty ItemsProperty =
DependencyProperty.Register(
"Items", typeof(List<LeafControlItem>), typeof(LeafControl),
new FrameworkPropertyMetadata(new List<LeafControlItem>(), null, null)
);
#endregion
请建议我在哪里做错了。