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.

3
  • 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. Commented Jan 10, 2013 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') Commented Jan 10, 2013 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 Commented Jan 10, 2013 at 17:17

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.