我创建了一个自定义控件以及在该控件中使用 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>