WPF Datagrid:当SelectionUnit ="Cell"时,不会引发SelectionChanged事件

GuY*_*YsH 8 wpf datagrid wpfdatagrid

我正在使用WPF工具包datagrid.我把它设置为SelectionUnit ="Cell"SelectionMode ="Extended".

SelectionChanged事件永远不会被提升!

当SelectionUnit设置为FullRow时,它可以正常工作.

我错过了什么吗?

顺便说一句,我需要它的原因是因为我正在尝试创建一个附加属性来帮助我将SelectedCells绑定到我的ViewModel.

Aar*_*ver 9

利用DataGrid.SelectedCellsChanged它应该为您提供所需的东西.

private void DG1_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
    //Get the newly selected cells
    IList<DataGridCellInfo> selectedcells = e.AddedCells;

    //Get the value of each newly selected cell
    foreach (DataGridCellInfo di in selectedcells)
    {
        //Cast the DataGridCellInfo.Item to the source object type
        //In this case the ItemsSource is a DataTable and individual items are DataRows
        DataRowView dvr = (DataRowView)di.Item;

        //Clear values for all newly selected cells
        AdventureWorksLT2008DataSet.CustomerRow cr = (AdventureWorksLT2008DataSet.CustomerRow)dvr.Row;
        cr.BeginEdit();
        cr.SetField(di.Column.DisplayIndex, "");
        cr.EndEdit();

    }
}
Run Code Online (Sandbox Code Playgroud)