Campl3r Campl3r - 4 months ago 36
C# Question

DataGrid set single cells readonly

I am looking for a way to disable some of my cells in a WPF DataGrid. Since isReadOnly is not a DependencyProperty, I can not use it.

Is there any other way to do this?

I would like to write something like this:

<DataGridTextColumn IsReadOnly="{Binding Path=Value,Converter={StaticResource ValueToBooleanConverter}}" />

but any way how to do this would be nice, since I don't see a way, but Splitting the data in different


If you can`t make a column read-only, you can go to a cell level. For example by making Style and adding it to required columns:

 <DataGridTextColumn Binding="{Binding TextProperty}">
           <Style TargetType="DataGridCell">
               <Setter Property="IsEnabled" 
                       Value="{Binding Path=Value,Converter={StaticResource ValueToBooleanConverter}}" />

I made the Style inside column here but of cource it can be moved to resources and referenced in any required columns by key (but you gotta be shure converter is accessible for that style). Cell`s IsReadOnly doesn`t seem to have a setter so I`m using IsEnabled here which is doing the job quite nicely.