ItemsSource项目正在重复

时间:2017-02-14 05:28:51

标签: c# xaml uwp

我有一个自定义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都会在其RibbonSectionItemsSource类型)属性中收到所有三个IList<RibbonSection>。如果我将ItemsSource绑定到List<RibbonSection>,它就可以了。这是XAML中的一个错误,还是它应该如何表现,我应该采取不同的做法?

0 个答案:

没有答案