During the change of focus from the DataGrid to the button, the binding update at CurrentCell triggered

  1. I select a row with a column triggered Binding CurrentCell (In the VM, the DatagridCellInfo updated)

  2. I click on the button to work again Binding CurrentCell (How not to let it work?) (The VM updates DatagridCellInfo to null ), it should not seem like a code (Although updatesourcetotriger=propertychanged ) and then

My XAML DataGrid :

 <DataGrid ItemsSource="{Binding Path=Collection}" SelectedItem="{Binding Path=SelectedPlaneMonth}" IsReadOnly="{Binding Path=IsReadOnly}" AutoGenerateColumns="False" CurrentCell="{Binding Path=DataGridCell, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ColumnWidth="*"/> 

My VM Code on CurrentCell

 public DataGridCellInfo DataGridCell { get => _dataGridCell; set { _dataGridCell = value; OnPopertyChanged("DataGridCell"); if (_dataGridCell.Column != null) { CheckBox content = _dataGridCell.Column.GetCellContent(_dataGridCell.Item) as CheckBox; if (content.IsChecked == true) { IsEnableButton = true; } else { IsEnableButton = false; } } } } 

My VM code on the ChangedCommand Button

 public PosukCommand ChangedCommand { get { return _changedCommand ?? (_changedCommand = new PosukCommand(obj => { if (_dataGridCell.Column != null) { using (PosukContext db = new PosukContext()) { PprCalendarPalneMonth palneMonth = _dataGridCell.Item as PprCalendarPalneMonth; var _day = palneMonth.GetType().GetField("Day" + _dataGridCell.Column.DisplayIndex.ToString()); } } })); } } 
  • one
    This is not similar to MVVM, the essence of MVVM is that View (thanks to the bindings built into WPF and the support of commands) is tied to an VM that knows nothing about it. You are manipulating some controls in VM explicitly ... - Andrew NOP
  • You can give a hint, like doing a textbook. View knows nothing and everything in VM is updated through bindes - Olzhas Alimbaev

0