我正在浏览WPF官方文档,如何:实现CompositeCollection,对CollectionContainer有一些疑问。
<ListBox.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{StaticResource greekGods}" />
<CollectionContainer Collection="{Binding Source={StaticResource greekHeroes}}" />
<ListBoxItem Background="red">Other ListBox Item 1</ListBoxItem>
<ListBoxItem Background="red">Other ListBox Item 2</ListBoxItem>
</CompositeCollection>
</ListBox.ItemsSource>
为什么 XMLDataProvider 资源
GreekHeroesData
必须使用 Binding?否则会抛出异常。
<CollectionContainer Collection="{Binding Source={StaticResource greekHeroes}}" />
但是CLR资源
GreekGodsData
可能会忽略它?
<CollectionContainer Collection="{StaticResource greekGods}" />
感谢您的帮助!
当我写下以下内容时:
<CollectionContainer Collection="{StaticResource greekHeroes}" />
它引发了异常:
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message=“An exception was thrown while setting the property 'System.Windows.Data.CollectionContainer.Collection'.”, the line number is "49", and the line position is "22".
Source=PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at CompositeCollections.MainWindow.InitializeComponent() in I:\github.com\learning-wpf\DataBinding\CompositeCollections\MainWindow.xaml : line 1
This exception was initially thrown in this call stack:
[external code]
Internal exception 1:
ArgumentException: 'System.Windows.Data.XmlDataProvider' is not a valid value for property 'Collection'.
感谢您的帮助!