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.
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;
...
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With