我有以下情况,工作正常:
<ListBox ItemsSource="{Binding Source={StaticResource cvs}}">
<ListBox.Resources>
<CollectionViewSource x:Key="csv" Source="{Binding Path=PropertyOnViewModel}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="GroupByProperty" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</ListBox.Resources>
</ListBox>
我尝试将其更改为
<ListBox>
<ListBox.ItemsSource>
<Binding>
<Binding.Source>
<CollectionViewSource Source="{Binding Path=PropertyOnViewModel}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="GroupByProperty" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Binding.Source>
</Binding>
</ListBox.ItemsSource>
</ListBox>
这不起作用,它会产生运行时绑定错误
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or
FrameworkContentElement for target element. BindingExpression:Path=PropertyOnViewModel;
DataItem=null; target element is 'CollectionViewSource' (HashCode=61730159); target
property is 'Source' (type 'Object')
第二个版本有什么问题?