Посмотрите на этот пост, проблема объяснена
Связывание в текстовом столбце таблицы данных WPF
а тут
http://blogs.msdn.com/b/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx
Цитирование JaredPar из первой ссылки
«По сути, проблема в том, что DataGridTextColumn не имеет родительского элемента для наследования привязки, поскольку она не является частью логического или визуального дерева. Чтобы получить доступ к информации привязки, необходимо настроить контекст наследования»
Обходной путь, чтобы заставить это работать ..
public class DataGridContextHelper
{
static DataGridContextHelper()
{
DependencyProperty dp = FrameworkElement.DataContextProperty.AddOwner(typeof(DataGridColumn));
FrameworkElement.DataContextProperty.OverrideMetadata(typeof(DataGrid),
new FrameworkPropertyMetadata
(null, FrameworkPropertyMetadataOptions.Inherits,
new PropertyChangedCallback(OnDataContextChanged)));
}
public static void OnDataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
DataGrid grid = d as DataGrid;
if (grid != null)
{
foreach (DataGridColumn col in grid.Columns)
{
col.SetValue(FrameworkElement.DataContextProperty, e.NewValue);
}
}
}
}
public partial class App : Application
{
static DataGridContextHelper dc = new DataGridContextHelper();
}
<DataGrid x:Name="c_dataGrid" AutoGenerateColumns="False" DataContext="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=SelectedItem}">
<DataGrid.Columns>
<DataGridTextColumn Visibility="{Binding Path=(FrameworkElement.DataContext), RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource HideColumnAConverter}}" />
</DataGrid.Columns>
</DataGrid>
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return Visibility.Visible;
}
// Whatever you're binding against
TestClass testClass = value as TestClass;
return testClass.ColumnAVisibility;
}