2017-10-05 183 views
0

我有一個datagrid綁定到可觀察集合,當我嘗試編輯單元格時,整個行也被編輯了。我已經嘗試了很多東西已經無濟於事。我甚至硬編碼了一個特定的索引,以便只有選中的單元格得到更新。下面的代碼讓我看到確切的單元格,但仍然更新整行。我能做什麼?wpf datagrid在單個單元格中更新全行編輯

<DataGrid Name="timetableGrid" AutoGenerateColumns="True" SelectionMode="Single" GridLinesVisibility="None" 
         CellEditEnding="timetableGrid_CellEditEnding" ItemsSource="{Binding Path=TimetableControlDetailsData, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
        IsSynchronizedWithCurrentItem="False" SelectionUnit="Cell" CurrentCell="{Binding CellInfo, Mode=OneWayToSource}" > 

       </DataGrid> 



private DataGridCellInfo _cellInfo; 
public DataGridCellInfo CellInfo 
{ 
    get { return _cellInfo; } 
    set 
    { 
     _cellInfo = value; 
     OnPropertyChanged("CellInfo"); 
    } 
} 

private void timetableGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) 
{ 
     var test = _vm.CellInfo; 
     var test1 = test.Item as TimetableControlDetail; 

     var xs = _vm.TimetableControlDetailsData.Where(c => c.DayID == test1.DayID && c.PeriodID == test1.PeriodID).ToList(); 
     var x = _vm.TimetableControlDetailsData.Where(c => c.DayID == test1.DayID && c.PeriodID == test1.PeriodID).FirstOrDefault(); 
     x.ClassInstanceDetail.ClassName = "excellent!"; 
} 

通過cellediting事件會後,在cellediting上面的代碼給我的只有1項變種X,但整行文字被更新爲優!太。我只想改變確切的當前細胞。謝謝

回答

0

這不是一個完美的解決方案。但是,爲什麼你不嘗試去掉整行更新一個單元,但它回來了?