Home > Net >  How to bind Itemsource of DataGridto the IsReadOnly property of the internal DataGridTextColumn?
How to bind Itemsource of DataGridto the IsReadOnly property of the internal DataGridTextColumn?

Time:02-10

I have a DataGrid (below) that takes in SimulatedItems as an ItemsSource which is from my viewmodel. The SimulatedItems is an ObservableCollection of SimulatedItem. Inside SimulatedItem there is a variable DriverID, NameID and Active. Both the DataGridTextColumns below correctly reference these variables inside for Binding but for IsReadOnly it does not work. It appears IsReadOnly is attempting to bind to my viewmodel rather than the SimulatedItems. How do I get IsReadOnly to bind to my item from ItemsSource?

<DataGrid Grid.Row="1" ItemsSource="{Binding SimulatedItems}">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="NameID" Binding="{Binding NameID}" IsReadOnly="{Binding Active}"></DataGridTextColumn>
                    <DataGridTextColumn Header="DriverID" Binding="{Binding Path=DriverID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding Active}"></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

CodePudding user response:

If i read your question correctly then this article on stackoverflow may help.

DataGridTextColumn.IsReadOnly seems to be faulty

  •  Tags:  
  • Related