我有一个自定义Ribbon
控件,它具有ItemsSource
依赖项属性。此属性是IList<RibbonItem>
的类型。我在XAML中设置ItemsSource
,如下所示:
<customcontrols:Ribbon.ItemsSource>
<customcontrols:RibbonItem x:Name="InsertRibbonItem"
Key="insert-item"
TabHeader="Insert">
<customcontrols:RibbonItem.ItemsSource>
<customcontrols:RibbonSection SectionHeader="Layout"
SeparatorColor="#ccc" />
</customcontrols:Ribbon.ItemsSource>
</customcontrols:RibbonItem>
<customcontrols:RibbonItem x:Name="DesignRibbonItem"
Key="design-item"
TabHeader="Design">
<customcontrols:RibbonItem.ItemsSource>
<customcontrols:RibbonSection SectionHeader="Layout"
SeparatorColor="#ccc" />
</customcontrols:RibbonItem.ItemsSource>
</customcontrols:RibbonItem>
<customcontrols:RibbonItem x:Name="ReviewRibbonItem"
Key="review-item"
TabHeader="Review">
<customcontrols:RibbonItem.ItemsSource>
<customcontrols:RibbonSection SectionHeader="Structure"
SeparatorColor="#ccc" />
</customcontrols:RibbonItem.ItemsSource>
</customcontrols:RibbonItem>
</customcontrols:Ribbon.ItemsSource>
问题在于,由于某种原因,每个RibbonItem
都会在其RibbonSection
(ItemsSource
类型)属性中收到所有三个IList<RibbonSection>
。如果我将ItemsSource
绑定到List<RibbonSection>
,它就可以了。这是XAML中的一个错误,还是它应该如何表现,我应该采取不同的做法?