0

I have a DataForm from System.Windows.Controls.Data.DataForm.Toolkit and I need to programmatically get the same result as after clicking Cancel on this DataForm.

I need that because this DataForm is in ChildWindow, and if I change something in DataForm and I close a ChildWindow, then changes will be commited. This shouldn't work in that way. When I close ChildWindow I want to discard all changes the same as after clicking Cancel Button.

I've tried

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
    dfColumnInfo.CancelEdit();

    base.OnClosing(e);
}

but it doesn't work.

Thank you in advance.

bugfinder suggested to add a code which saves changes. There is no such thing, because childWindow has an editedObject as a DataContext

childWindow.DataContext = table;
childWindow.MyDataForm.DataContext = table.Items;
childWindow.Show();

I don't know how how, but Cancel button of DataForm reverts all changes which I've done in DataForm, which is a great think. But how to get the same effect by using some other button of childWindow, or just by closing childWindow?

Phil
  • 42,255
  • 9
  • 100
  • 100
user278618
  • 19,306
  • 42
  • 126
  • 196

1 Answers1

0

I searched for you, and found some useful stuff here: http://forums.silverlight.net/t/112449.aspx/1

Then tested like this:

void dform_EditEnded(object sender, DataFormEditEndedEventArgs e)
{
    if (e.EditAction != DataFormEditAction.Commit)
    {
        (dform.CurrentItem as MyEntity).RejectChanges();
        return;
    }
}

To achieve this goal the MyEntity must be public as I coded its partial below. I'm sharing word from silverlightnet forum "To be able to call RejectChanges (which is a protected method of the System.Windows.Ria.Entity class, we have to make it public"

public partial class MyEntity:Entity
{
   public void RejectChanges()
   {
       if (HasChanges)
           base.RejectChanges();
   }
}

Hope this helps.

Phil
  • 42,255
  • 9
  • 100
  • 100
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83