Set DataGridTemplateColumn Control to ReadOnly in WPF
Hi all, There was a question raised on how to set a control (ex. TextBox) inside the DataGridTemplateColumn of a WPF DataGrid to ReadOnly. The solution to that is to get the DataGridRow followed by accessing the DataGridCell and then get the VisualChild control inside the DataGridCell. By then, you can set the control's property IsReadOnly to true . XAML Code <DataGrid x:Name= "dgPerson" Grid.Column= "2" Grid.Row= "2" CanUserDeleteRows= "False" AutoGenerateColumns= "False" CanUserAddRows= "False" > <DataGrid.Columns> <DataGridTemplateColumn Header= "ID" Width= "150" > <DataGridTemplateColumn.CellTemplate> <DataTemplate > <TextBox Name= "txtID" Text= "{Binding ID, Mode=OneWay}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn H