I execute LogInRequest()
which calls LogInView.ShowDialog()
. That view has a Command called VerifyLogInCommand
. When the Command is executed, it completes with this.CloseAction()
which appears to close the Dialog. However, my breakpoint in that view's command's CanExecute method VerifyLogInCanExecute
is still being hit after the dialog is closed (nonstop). I've tried setting the view to null after calling ShowDialog but no change.
Why is the Command/CanExecute still being evaluated when the window is closed/null?
LogInView.xaml.cs
public LogInOutView()
{
InitializeComponent();
// Data context
IModule existingVM = SessionViewModel.Instance.ModulesOpen.Single(mod => mod.ModuleName == "LogIn");
LogInViewModel livm = (LogInViewModel)existingVM;
this.DataContext = livm;
// Cancel Handler
livm.CloseAction = new Action(() => this.Close());
}
LogInViewModel.cs
public Action CloseAction { get; set; }
private RelayCommand verifyLogInCommand;
public RelayCommand VerifyLogInCommand
{
get
{
if (verifyLogInCommand == null)
{
verifyLogInCommand = new RelayCommand(
param => VerifyLogInExecute(),
param => VerifyLogInCanExecute);
}
return verifyLogInCommand;
}
}
public void VerifyLogInExecute()
{
// Validate Login
Employee employee = ValidateLogin(Password);
// Clear password field
ResetExecute();
// Return false if invalid login
if (employee == null)
{
Result = LogInOutDialogResults.Cancel;
ConfirmationView c = new ConfirmationView("Invalid Login!");
c.ShowDialog();
return;
}
// Set Result to LogIn status
Result = LogInOutDialogResults.LogIn;
// Set LastAuthorizedEmployee
SessionViewModel.Instance.LastAuthorizedEmployee = employee;
// Close View to go back where it was called
this.CloseAction();
}
public bool VerifyLogInCanExecute
{
get
{
// Password length restrictions
if (!CheckRequiredPasswordLength(Password)) { return false; }
return true;
}
}
public static LogInOutDialogResults LogInRequest()
{
// Show Login View
LogInOutDialogResults LogInOutResult = LogInOutDialogResults.Cancel;
LogInOutView LogInOutView = new LogInOutView()
{
Title = "Log In",
ShowInTaskbar = false,
Topmost = true,
ResizeMode = ResizeMode.NoResize,
Owner = SessionViewModel.Instance.ProfitPOSView
};
LogInOutView.ShowDialog();
LogInOutResult = ((LogInViewModel)LogInOutView.DataContext).Result;
// LogIn
if (LogInOutResult == LogInOutDialogResults.LogIn)
{
LogInOutView = null;
return LogInOutDialogResults.LogIn;
}
}