WPF Data Binding error 2: Cannot find governing FrameworkElement…


I got this error when trying to bind to a collection element, which was not derived from the FrameworkElement (just DependencyObject) and was thus not inheriting it’s container’s DataContext, e.g.

<Grid>
   <Grid.DataContext>
      <loc:MyViewModel />
   </Grid.DataContext>
   <igRibbon:XamRibbon Grid.Row=”0″ x:Name=”ribbon”>
      <igRibbon:XamRibbon.ContextualTabGroups>
         <igRibbon:ContextualTabGroup Key=”SelectionGroup” Caption=”Contextual Tabs” IsVisible=”{Binding IsContextualTabVisible}”>
             <igRibbon:ContextualTabGroup.Tabs>

I tried replaing the binding with ElementName=ribbon,Path=DataContext.IsContextualTabVisible but that was not resolvable either – I assume ElementName=ribbon needed the framework hierarchy to find element named ‘ribbon’.

Solution which worked was to define the data context object as a resource and consume it both as a DataContext and Source reference on the problematic binding

<Grid>
   <Grid.Resources>
      <loc:MyViewModel x:Key=”VM” />
   </Grid.Resources>
   <Grid DataContext=”{StaticResource VM}”>
      <igRibbon:XamRibbon Grid.Row=”0″ x:Name=”ribbon”>
         <igRibbon:XamRibbon.ContextualTabGroups>
            <igRibbon:ContextualTabGroup Key=”SelectionGroup” Caption=”Contextual Tabs” IsVisible=”{Binding Source={StaticResource VM},Path=IsContextualTabVisible}”>
               <igRibbon:ContextualTabGroup.Tabs>

Comments (0)

Skip to main content