Never do this with a DataGrid. Usually, when I need to manage something similar, I use a ListBox and a DataTemplate with a grid inside to give it an idea of ββthe Grid or ListView with the GridView in the template, because they both give you more control over the interaction.
A snapshot in the dark as you bind, you can use the DataGridTemplateColumn.CellEditingTemplate and create your own Delete button / text that is visible or enabled based on the logic in your binding object. Maybe something like this (I have not tested this, but it should be a direction that you can lead)?
<dg:DataGridTemplateColumn Header="Action"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Text Content="Delete" /> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> <dg:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <ButtonEnabled="{Binding Path=IsDeleteEnabled, Mode=OneWay}" Content="Delete" Command="{Binding Path=DeleteMe}" /> </DataTemplate> </dg:DataGridTemplateColumn.CellEditingTemplate> </dg:DataGridTemplateColumn>
Using this method, since the command is bound to a single object, you may have to raise an event that your ViewModel is processing to remove this line from the ObservableCollection.
Again, not sure if this is the best way, but this is my 10 minute hit. So if this is terrible, please do not drive me away too much.
Josh
source share