【问题标题】:Using IEditableObject In Silverlight在 Silverlight 中使用 IEditableObject
【发布时间】:2009-08-14 16:49:40
【问题描述】:

我有一个对象,它实现了在绑定到 Silverlight 页面的视图模型上公开的 IEditableObject 接口。

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

我没有使用 DataGrid 或 DataForm 控件。我正在使用 Label、TextBox 和 DescriptionViewer 控件来显示数据以进行编辑。

【问题讨论】:

    标签: silverlight silverlight-3.0


    【解决方案1】:

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

    我是这样做的:

    只要当前项目(例如 CollectionViewSource)发生变化,就会这样做:

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

    每当我想保存(当前项目)时,我都会这样做:

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

    每当我想取消(当前更改)时,我都会这样做:

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

    希望它对未来的人有所帮助!

    【讨论】:

    • 虽然这不是我某些问题的确切答案,但给出的示例代码(以及我发布此问题以来的时间)给了我一些想法。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多