Greetings,
I am trying to bind the column visible to my viewmodel bool property and I am getting binding errors that I figured would work. I get an error in the output window stating..
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Xceed.Wpf.DataGrid.DataGridControl', AncestorLevel='1''. BindingExpression:Path=DataContext.IsNameVisible; DataItem=null; target element is 'Column' (HashCode=41921117); target property is 'Visible' (type 'Boolean')
Here is my snippet
<
xcdg:DataGridControl SelectionMode="Single" AutoCreateColumns="False"
ItemsSource="{Binding Source={StaticResource SearchResults}}">
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="Name" Title="Name" Visible="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataGridControl},}, Path=DataContext.IsNameVisible, Mode=TwoWay}" />
.. other columns removed for ease.
</xcdg:DataGridControl.Columns>
<xcdg:DataGridControl.View>
<xcdg:TableView AllowColumnChooser="False">
<xcdg:TableView.Theme>
<xcdg:Office2007BlueTheme />
</xcdg:TableView.Theme>
</xcdg:TableView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
I want do have a couple of canned views in the viewmodel that a user can choose via a drop down list that would automatically hide/show columns all at once and not have the user use the ColumnChooser.
I was also thinking if I could gain access to the ColumnChooser in code, maybe I could loop through the collection and update the columnchooser bool that way as well. is that possible?
Thanx