Cannot find governing FrameworkElement or FrameworkContentElement for target element

Oct 8, 2008 at 6:48 PM
Edited Oct 8, 2008 at 6:52 PM
I am attempting to bind a CollectionViewSource's Source property to the ItemsSource of a DataGrid.  But when I do this I see the following error in the Output window of Visual Studio, and the binding doesn't work:

Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ItemsSource; DataItem=null; target element is 'CollectionViewSource' (HashCode=49205706); target property is 'Source' (type 'Object')

My XAML looks something like this:


<dg:DataGrid x:Name="dgDocumentList" ItemsSource="{Binding Path=BusinessCloseItems}">



<dg:DataGridTextColumn Width="Auto" Header="Batch" DataFieldBinding="{Binding Path=BatchId}">












<CollectionViewSource Source="{Binding ElementName=dgDocumentList, Path=ItemsSource}" x:Key="cvsBatch">






<PropertyGroupDescription PropertyName="BatchId"/>












<StackPanel Orientation="Horizontal">



<TextBlock Text="{Binding}" VerticalAlignment="Center"/>



<ComboBox ItemsSource="{Binding Source={StaticResource cvsBatch}, Path=Groups}" DisplayMemberPath="Name"/>















The CollectionViewSource binding works fine if I bind to an element such as ListBox.  It's only when I try to bind to a DataGrid that I get the error.

Any ideas?


Oct 8, 2008 at 7:21 PM
Well it seems that if I move my CollectionViewSource out of the DataTemplate resources and into the top-level resources, it works.  I get the same behavior with a ListBox, so it must be XAML-related behavior, and not the DataGrid.