Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event for "DataContextChanging"?

I am very new to WPF so forgive me if the question doesn't make sense. Is there an event that is fired before data context change? I want to commit the pending data changes before the data context is switched away.

like image 305
NS.X. Avatar asked Feb 05 '12 21:02

NS.X.


2 Answers

There is no DataContextChanging event, but the DataContextChanged event provides the old value of the DataContext:

private void Window_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
    object oldDataContext = e.OldValue;
    ...
}
like image 159
Thomas Levesque Avatar answered Nov 13 '22 06:11

Thomas Levesque


There is no such event, if you want to make sure data is saved or that the user can choose to abort edits you should look into navigational architectures where screens are changed in a managed way.

like image 30
H.B. Avatar answered Nov 13 '22 06:11

H.B.