I have a datagrid bound to a list of objects. One of the properties of the object is called 'NoOutput' and if it is set, I want to disable certain other columns in the same row ('Value' in this example) in the datagrid, so the user cannot edit those values, as long as 'NoOutput' is set.
<DataGrid SelectionUnit="FullRow" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding Path=OutputList}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="2*" IsReadOnly="True" Binding="{Binding NameID}" />
<DataGridTextColumn Header="Description" Width="4*" Binding="{Binding TemplateDescription}" />
<DataGridCheckBoxColumn Header="NoOutput" Width="*" Binding="{Binding NoOutput}" />
<DataGridTextColumn Header="Value" Width="*" Binding="{Binding Value}" IsReadOnly="{Binding NoOutput, Converter={StaticResource Invert}}" />
</DataGrid.Columns>
</DataGrid>
The problem is, the binding of the IsReadyOnly property does not seem to bind against the same source, as the Binding property of the DataGridTextColumn.
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=NoOutput; DataItem=null; target element is 'DataGridTextColumn' (HashCode=45236668); target property is 'IsReadOnly' (type 'Boolean')
It looks like the IsReadOnly binding only sees the datacontext of the DataGrid, but not that of the DataGridColumn. I tried binding with relative source, but this did not work either. I also tried binding against the content of the SelectedItem, but I also couldn't get this to work. Is it possible to bind against a value of another column, but the same row of the datagrid?
(everything works, except the IsReadOnly binding)