Binding IsHidden with findancestor not working

hi,

i want to bind the IsHidden property of a sfdatagrid columns to a property in my viewmodel,
based on this page it's possible :
https://www.syncfusion.com/kb/2476/how-to-bind-the-gridcolumn-ishidden-property-to-property-in-viewmodel


here is my markup :
  <Syncfusion:GridTextColumn HeaderText="Début" MappingName="ORDD_START_DATE" 
                                              
                                               
                                                  IsHidden="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:TestVisibility}},Path=DataContext.IsHidden}"/>

but it didn't work , in the output window i have this message

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='CardioOne.Tests.TestVisibility', AncestorLevel='1''. BindingExpression:Path=DataContext.IsHidden; DataItem=null; target element is 'GridTextColumn' (HashCode=18580737); target property is 'IsHidden' (type 'Boolean')

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='CardioOne.Tests.TestVisibility', AncestorLevel='1''. BindingExpression:Path=DataContext.IsHidden; DataItem=null; target element is 'GridTextColumn' (HashCode=4566824); target property is 'IsHidden' (type 'Boolean')



i am using the latest version (16.1460.0.32)

thanks for your help .


1 Reply

JG Jai Ganesh S Syncfusion Team April 12, 2018 06:35 AM UTC

Hi Issam, 
 
In our KB article we have set the AncestorType as MainWindow that is the DataContext is set in MainWindow. 
 
<syncfusion:GridTextColumn IsHidden="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MainWindow}},Path=DataContext.Hide}" MappingName="EmployeeArea"/> 
 
Your code seems that you have used the AncestorType as 'CardioOne.Tests.TestVisibility' and AncestorLevel='1'' in your application. Could you please let us know the details on how you have defined this in Xaml? If possible please share the complete sample or else share the Xaml and view model file? This would be more helpful for us to proceed further. 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon