1

I got a WPF DataGrid and in the DataGrid i want to have a column displayed dependent on a property outside of the DataGrid Context (from the ViewModel).

I have the same Property binding outside of the DataGrid for some labels (without the "DataContext." ) and this works fine.

<DataGrid ItemsSource="{Binding Items.View}" AutoGenerateColumns="False"   x:Name="Overview" >

<DataGridTemplateColumn Header="{lex:Loc Value}" Width="Auto" Visibility="{Binding ElementName=Overview, Path=DataContext.CharacteristicMeasure.Characteristic.CharacteristicType.IsBool,Converter={StaticResource boolToInv}, ConverterParameter=true}" >
  <DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
          <TextBlock Text="{Binding Value}" />
      </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
  <DataGridTemplateColumn.CellEditingTemplate>
      <DataTemplate>
          <TextBox Text="{Binding Value}"  />
      </DataTemplate>
  </DataGridTemplateColumn.CellEditingTemplate>
  </DataGridTemplateColumn>
</DataGridTemplateColumn>

Somehow this isnt effecting the Visibility property of the DataGridTemplateColumn at all. I dont know why and how to continue.

UPDATE

My output windows shows the following error:

    System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.CharacteristicMeasure.Characteristic.CharacteristicType.IsBool; DataItem=null; target element is 'DataGridTemplateColumn' (HashCode=15721293); target property is 'Visibility' (type 'Visibility')

UPDATE 2

though i got the same Property Binded on another Visibility Property outside of the DataGrid

    <DockPanel Visibility="{Binding CharacteristicMeasure.Characteristic.CharacteristicType.IsBool,Converter={StaticResource boolToInv}, ConverterParameter=true}" >...

and this works fine.

Yael
  • 1,566
  • 3
  • 18
  • 25
JuHwon
  • 2,033
  • 2
  • 34
  • 54
  • Attach your debugger and put a breakpoint in your converter's ConvertTo method. That should verify that your property is wired up correctly and that the converter is converting it to a Visibility enum. – Gishu Jan 10 '13 at 15:35
  • Converter isnt executed. i get the following output: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.CharacteristicMeasure.Characteristic.CharacteristicType.IsBool; DataItem=null; target element is 'DataGridTemplateColumn' (HashCode=15721293); target property is 'Visibility' (type 'Visibility') – JuHwon Jan 10 '13 at 15:43
  • Doh! Bitten by this again - DataGridColumn isn't a visual element. possible duplicate of [Binding to Visible property DataGridCOlumn in WPF DataGrid](http://stackoverflow.com/questions/669060/binding-to-visible-property-datagridcolumn-in-wpf-datagrid) – Gishu Jan 10 '13 at 17:17

1 Answers1

1

As strange as it sounds, the DataGridColumn class inherits directly from DependencyObject, so you can't use bindings on its properties (it has no SetBinding method).

Can't figure out why.

Nicolas Repiquet
  • 9,097
  • 2
  • 31
  • 53
  • Thank you. Now i do understand the Problem and already fixed it. I did bind the Property to the TextBox and display another TextBox with the inverted version of this converter. Thanks – JuHwon Jan 10 '13 at 16:14