0

我创建了一个自定义控件以及在该控件中使用 ContentControl 以使用 MVVM 设计模式,但是当我运行应用程序时,我的控件不喜欢这样。为了测试,我还尝试了其他标准控件,但它们都不能在自定义控件中工作......只是更多依赖于父自定义控件的自定义控件。

是否有人建议如何将标准控件(例如 ContentControl )放置在自定义控件中?

干杯。

编辑

XamlParseException -> '向'System.Collections.ObjectModel.ObservableCollection(Ribbon_Framework.RibbonTabItem)' 类型的集合添加值引发异常。' 行号“8”和行位置“14”。

    <Ribbon:Ribbon AutomaticStateManagement="True" x:Name="Ribbon">
        <ContentControl x:Name="SearchRibbon" Content="{Binding Path=SearchRibbon}" ContentTemplate="{DynamicResource SearchRibbonTemplate}" />
    </Ribbon:Ribbon>

在内容控件内部->

<DataTemplate x:Key="SearchRibbonTemplate">
    <ItemsControl ItemsSource="{Binding}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Ribbon:RibbonTabItem Header="Search">
                    <Ribbon:RibbonGroupBox Header="{Binding Path=DisplayName}" Width="100">
                        <Ribbon:Button Width="100" Icon="{Binding Path=TemplateResource}" LargeIcon="{Binding Path=TemplateResource}" Command="{Binding Path=Commands}" />
                    </Ribbon:RibbonGroupBox>
                </Ribbon:RibbonTabItem>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</DataTemplate>
4

1 回答 1

1

您的 Ribbon 控件需要一个 RibbonTabItem 类型的对象(因为它包含一个

ObservableCollection<RibbonTabItem> 

所以您只能将 RibbonTabItem 类添加到其中 - 您需要确保您的控件允许其中的其他元素。一些第 3 方控件通过在其自定义控件的内部项中提供内容控件(即让 RibbonTabItem 在其中包含 ContentControl)或允许您自定义项模板来解决此问题

您需要更改 Ribbon 的实现或更改 RibbonTabItem 的功能才能使其正常工作。查看 ItemsControl.Items 属性,看看它是什么类型。您应该尝试为您的 ObservableCollection 使用该类型

于 2012-07-07T17:55:26.083 回答