在Silverlight中使用IEditableObject

Dav*_*veB 1 silverlight silverlight-3.0

我有一个对象,它实现了在绑定到Silverlight页面的viewmodel上公开的IEditableObject接口.

如何/在哪里调用BeginEdit,CancelEdit和EndEdit方法?如何仅将实现此接口的对象约束到我的页面?

我没有使用DataGrid或DataForm控件.我使用Label,TextBox和DescriptionViewer控件来显示要编辑的数据.

Sav*_*dis 6

我知道这是一个旧线程(但为了将来使用...)

我是这样做的:

每当当前项(例如CollectionViewSource)发生更改时,都会执行以下操作:

void View_CurrentChanged(object sender, EventArgs e)
        {
            if (culturesView.Source != null)
            {
                ((IEditableObject)SelectedRecord).BeginEdit();
                RaisePropertyChanged("SelectedRecord");

            }
        }
Run Code Online (Sandbox Code Playgroud)

每当我想保存(当前项目)我这样做:

 private void Save()
{
 ((IEditableObject)SelectedRecord).EndEdit();
//do the actual saving to the dbms here ....

}
Run Code Online (Sandbox Code Playgroud)

每当我想取消(当前的变化),我这样做:

private void Cancel()
{            
((IEditableObject)SelectedRecord).CancelEdit();
            //allthough we have canceled the editing we have to re-enable the edit mode (because
            //the user may want to edit the selected record again)
            ((IEditableObject)SelectedRecord).BeginEdit();

}
Run Code Online (Sandbox Code Playgroud)

希望它能帮助将来的某个人!