Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
Binding to the XamDataGrid Field Visibility Property Fails
posted

I downloaded and followed the sample from Josh Smith on "Binding a XamDataGrid Field Property" as shown here http://forums.infragistics.com/blogs/josh_smith/archive/2008/06/06/binding-a-xamdatagrid-field-property.aspx

However, the sample doesn't work if I change the Binding Source of the Field Visibility from <Binding Path="ShowPhotos" Source="{StaticResource DATA_CommunityViewModel}">  to <Binding  Path="DataContext.ShowPhotos" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}"> I get the following in the Output Window:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Window', AncestorLevel='1''. BindingExpression:Path=DataContext.ShowPhotos; DataItem=null; target element is 'Field' (HashCode=23181364); target property is 'Visibility' (type 'Visibility')

 

I also tried by changing the ancestor type to the name of the Window (I gave it a name) and have the source as <Binding  Path="DataContext.ShowPhotos" ElementName="MyWindowName"> but I get the following error:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.ShowPhotos; DataItem=null; target element is 'Field' (HashCode=11653293); target property is 'Visibility' (type 'Visibility')

 

I didn't think changing the Binding to use the ElementName or the RelativeSource would fail. Is there any reason why this doesn't work? Is my code incorrect? Please let me know. Thanks in advance.

  • 69686
    posted

    Hello,

    The Fields are not part of the visual tree of the application, so any bindings will not work.

    The DATA_CommunityViewModel is specifically designed to overcome this. The change you have made is just the opposite. The error you are seeing is that no framework element cannot be found for that binding - because the fields are not in the visual tree.