This is a migrated thread and some comments may be shown as answers.

System.Windows.Data Error = 2

5 Answers 676 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 03 Jun 2014, 06:01 PM
I'm seeing an odd error with the grouping in the RadGridView. It's worth pointing out that the data is being displayed and grouped properly despite the error. However, I still want it resolved.

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Columns[ContactType]; DataItem=null; target element is 'ColumnGroupDescriptor' (HashCode=34214014); target property is 'Column' (type 'GridViewColumn')

Below is the relevant portion of my XAML. The extra columns have been elided as is the rest of the visual tree. I get the same problem if it's in different parts of the visual tree and even with just the one column.

​<telerik:RadGridView x:Name="ContactsGridView"
                        ItemsSource="{Binding Employee.Contacts}">
    <telerik:RadGridView.Columns>
        <telerik:GridViewComboBoxColumn Header="Type" UniqueName="TypeColumn"
                                        ItemsSource="{Binding ContactTypesView}"
                                        DataMemberBinding="{Binding ContactTypeId}"
                                        SelectedValueMemberPath="Id" DisplayMemberPath="TypeName"
                                        EditTriggers="CellClick" ShowColumnWhenGrouped="False" />
    </telerik:RadGridView.Columns>
    <telerik:RadGridView.GroupDescriptors>
        <telerik:ColumnGroupDescriptor Column="{Binding Columns[\TypeColumn\], ElementName=ContactsGridView}"
                                        SortDirection="Ascending" />
    </telerik:RadGridView.GroupDescriptors>
</telerik:RadGridView>

I have a style that governs the several grids in my window. Here is that XAML:

<Style TargetType="{x:Type telerik:RadGridView}">
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="GridLinesVisibility" Value="None" />
    <Setter Property="ShowGroupPanel" Value="False" />
    <Setter Property="RowIndicatorVisibility" Value="Collapsed" />
    <Setter Property="RowDetailsVisibilityMode" Value="Collapsed" />
    <Setter Property="AutoGenerateColumns" Value="False" />
    <Setter Property="CanUserFreezeColumns" Value="False" />
    <Setter Property="SelectionUnit" Value="FullRow" />
    <Setter Property="AutoExpandGroups" Value="True" />
    <Setter Property="GroupRenderMode" Value="Flat" />
</Style>

Any ideas of what might be causing this error? I created a stripped down solution and couldn't duplicate the error message.

5 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 06 Jun 2014, 02:50 PM
Hello Anthony,

We tried to reproduce the mentioned BindingExpressions. However, we were unsuccessful. In order to reproduce the error, could you please modify the attached sample project and send it back to us so that we can debug it on our side ?


Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Anthony
Top achievements
Rank 1
answered on 11 Jun 2014, 12:02 AM
Odd. My previous reply didn't get posted. In it I had indicated that I hadn't been able to reproduce it. Tonight I messed with it some more and I was able to get the magical combination without pasting my entire application.

Essentially, Error: 2:Cannot find governing FrameworkElement or FrameworkContentElement for target element occurs when the RadGridView is inside a RadExpander.

<telerik:RadExpander>
     <telerik:RadGridView ...>
          ...
     </telerik:RadGridView>
</telerik:RadExpander>
0
Boris
Telerik team
answered on 12 Jun 2014, 02:37 PM
Hello Anthony,

We were successful in reproducing the issue. 
The reason for this issue is that the Column property of the ColumnGroupDescriptor is bound to "{Binding Columns[\Country\], ElementName=pilotsGrid}". This is an issue because the WPF Framework reads initially through the XAML and at that point the pilotsGrid still does not exist (RadExpander is not yet expanded). In order to resolve this you can use a GroupDescriptor instead of the ColumnGroupDescriptor one.

<telerik:RadGridView.GroupDescriptors>
        <telerik:GroupDescriptor Member="CountryId" SortDirection="Ascending" />
</telerik:RadGridView.GroupDescriptors>

Also, I attached a sample project that demonstrates the suggested approach.

I hope this helps.


Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Anthony
Top achievements
Rank 1
answered on 12 Jun 2014, 03:43 PM
Thanks. That works great. I wasn't aware of the GroupDescriptor.

I was a little concerned about it working, because my member is a key value and not a discrete value (and I obviously don't want to show the key value). However, this uses the rules of the column to show the name of the contact type just like a column.
0
Aliaster
Top achievements
Rank 1
answered on 03 May 2017, 09:08 AM
Firstly, this message will not do affect your binding part, if you want to know the reason, I think you could add a Converter to debug your binding: You could also try the Windows Data Recovery Tool by SysInfoTools a leading software firm developing high end software utilities  
Tags
GridView
Asked by
Anthony
Top achievements
Rank 1
Answers by
Boris
Telerik team
Anthony
Top achievements
Rank 1
Aliaster
Top achievements
Rank 1
Share this question
or