我正在尝试处理数据来自外部数据的内部添加/删除/编辑命令表单按钮控件。我正在使用MVVMLight。例如:要在删除按钮中删除按钮EventToCommand i Bind Command =“{Binding DeleteCurrentItemInDataform,Mode = TwoWay}” CommandParameter =“{Binding CurrentItem,ElementName = Dataform1}”
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");
}
}
答案 0 :(得分:2)
我发现使用后面的代码非常简单: 例如,对于编辑,只需要做&gt; Datafrom1.BeginEdit();