I am trying to implement so guard handling with Caliburn.Micro but I am getting an invalid cast exception when the application runs.
The Property:
public Account UserAccount
{
get
{
return account;
}
set
{
account = value;
NotifyOfPropertyChange(() => UserAccount);
NotifyOfPropertyChange(() => CanSaveAndNavigateToComposeView());
}
}
The Method:
public void SaveAndNavigateToComposeView()
{
CommitAccountToStorage();
navigationService.UriFor<ComposeViewModel>().Navigate();
}
The Guard:
public bool CanSaveAndNavigateToComposeView()
{
return !(string.IsNullOrEmpty(UserAccount.DisplayName) ||
string.IsNullOrEmpty(UserAccount.Username) ||
string.IsNullOrEmpty(UserAccount.Password) ||
string.IsNullOrEmpty(UserAccount.ServerSymbol));
}
The guard works if I take out the notify prop change on the property but this means my method would never evaluate.
You need to make CanSaveAndNavigateToComposeView into a property rather than a method.