Event for "DataContextChanging"?

NS.X. picture NS.X. · Feb 5, 2012 · Viewed 15.5k times · Source

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.

Answer

Thomas Levesque picture Thomas Levesque · Feb 6, 2012

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;
    ...
}