// Global exception handling // (event handler registered in App.xaml) void Application_DispatcherUnhandledException( object sender, DispatcherUnhandledExceptionEventArgs e ) { if ( e.Exception is NotLicensedException ) { ShowErrorMessageBox( "You don't have a license for this feature" ); e.Handled = true; // Redirect them to the activation dialog so they can install a valid license var activationDialog = new ActivationDialog { Owner = MainWindow }; activationDialog.ShowDialog(); } else { //All other exceptions string exceptionMessage = e.Exception != null ? e.Exception.Message : e.ToString(); ShowErrorMessageBox( "An error occurred: " + exceptionMessage ); e.Handled = false; } }
void ShowActivationDialog_Click( object sender, RoutedEventArgs e ) { var activationDialog = new ActivationDialog { Owner = this }; // ((ViewModelBase)activationDialog.DataContext).DisplayState = this; activationDialog.ShowDialog(); }