Using IEditableObject In Silverlight

倖福魔咒の 提交于 2020-01-14 03:11:34

问题


I have a object that implements the IEditableObject interface exposed on a viewmodel bound to a Silverlight page.

How/Where do I call the BeginEdit, CancelEdit and EndEdit methods? How can I constrain only objects implementing this interface to my page?

I am NOT using DataGrid or DataForm controls. I am using Label, TextBox and DescriptionViewer controls to display the data for editing.


回答1:


I know this is an old thread (but for the sake of future use...)

I do it this way:

whenever the current item (for instance of a CollectionViewSource) changes this is done:

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

            }
        }

Whenever i want to save (the current item) i do this:

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

}

Whenever i want to cancel (current changes) i do this:

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();

}

Hope it helps someone in the future!



来源:https://stackoverflow.com/questions/1278942/using-ieditableobject-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!