I am trying to handling datafrom's internal Add/Delete/Edit command form button control outside datafrom. I am using MVVMLight so. For example : To have Delete in delete button EventToCommand i Bind Command="{Binding DeleteCurrentItemInDataform, Mode=TwoWay}" CommandParameter="{Binding CurrentItem, ElementName=Dataform1}"
In ViewModel code:
DeleteCurrentItemInDataform=new RelayCommand<DataForm>(e=>{ e.DeletingItem+=new EventHandler<CancelEventArgs>(DeletingCurrentItem); });
private void DeletingCurrentItem(object sender, CancelEventArgs e){
Cash cd = sender as Cash;
_DataContext.CashDrawers.Remove(cd);
_DataContext.SubmitChanges((op) => { if (op.HasError) {MssageBox.Show(op.Error.Message); } else{ MessageBox.Show(cd.CashName + " is deleted."); } }, null); }
private RelayCommand<DataForm> _deleteCurrentItemInDataform;
public RelayCommand<DataForm> DeleteCurrentItemInDataform
{
get { return _deleteCurrentItemInDataform; }
set
{
if (_deleteCurrentItemInDataform != value)
{
_deleteCurrentItemInDataform = value;
RaisePropertyChanged("DeleteCurrentItemInDataform");
}
}