Event for "DataContextChanging"?

I am very new to WPF, so forgive me if the question makes no sense. Is there an event that fires before the data context changes? I want to commit pending data changes before disabling the data context.

+5
source share
2 answers

There is no event DataContextChanging, but the event DataContextChangedcontains the old value DataContext:

private void Window_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
    object oldDataContext = e.OldValue;
    ...
}
+18
source

There is no such event, if you want to make sure that the data is saved or that the user can choose to discard the changes, you should study the navigational architecture where the screens change in a controlled way.

+3
source

All Articles