Error on guard clause with Caliburn.Micro

2019-06-04 07:18发布

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.

1条回答
闹够了就滚
2楼-- · 2019-06-04 07:55

You need to make CanSaveAndNavigateToComposeView into a property rather than a method.

查看更多
登录 后发表回答