0

I need to write functionality such that if the user leaves the UserControl (i.e. navigates away from the control), I need to save the data which resides in the view model of the user control.

I've tried connecting a handler to the Unloaded event of the user control, but I'm unable to access the DataContext.

Is there a way by which I can capture the event so I can save the data of the view model associated with the user control.

Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56
Prakash Chandra
  • 317
  • 1
  • 3
  • 14

1 Answers1

2

Use the LostFocus event instead of the Unloaded, because the Unloaded event won't necessarily be raised if the user navigate to another control.

From the event handler in your Code Behind file, you should have access to the DataContext.

mgarant
  • 565
  • 5
  • 18
  • +1, note that you can use an interaction trigger if you don't want to write any code behind: http://stackoverflow.com/a/21942689/2428407 – vesan May 12 '15 at 23:16