This seems a bit bizzare: I have a Datagrid with a button column which deletes the row when the button for that row is clicked. BUT if I set the Datagrid SelectionUnit="Cell" then the button column is disabled and I can no longer click the button.
Can anyone tell me why this happens and how to avoid the disabling behaviour for the column?
Here is XAML that recreates the issue - add & remove the SelectionUnit="Cell" to see the change in behaviour
<Window.Resources>
<local:DummyCollection x:Key="stringCollection">
<local:Dummy x="1" y="2" z="3" />
<local:Dummy x="4" y="5" z="6" />
<local:Dummy x="7" y="8" z="9" />
</local:DummyCollection>
</Window.Resources>
<StackPanel>
<DataGrid ItemsSource="{Binding Source={StaticResource stringCollection}}" AutoGenerateColumns="False" SelectionUnit="Cell">
<DataGrid.Columns>
<DataGridTextColumn x:Name="a" Binding="{Binding Path=x}" Header="a" />
<DataGridTextColumn x:Name="b" Binding="{Binding Path=y}" Header="b" />
<DataGridTextColumn x:Name="c" Binding="{Binding Path=z}" Header="c" />
<DataGridTemplateColumn x:Name="deleteButtonColumn" Header="D">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Command="Delete" >D</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
Add this to the Window's code behind:
public class Dummy
{
public string x { get; set; }
public string y { get; set; }
public string z { get; set; }
}
public class DummyCollection : ObservableCollection<Dummy> { }