private void CreatePasswordOnClosing(object sender, CancelEventArgs e) { var dialog = sender as CreatePassword; if (dialog != null) { var vm = dialog.DataContext as CreatePasswordViewModel; if (vm != null) { ExchangeManager.ChangePassword(vm.Password); OnSettingsLoaded(); } dialog.Closing -= CreatePasswordOnClosing; } }