Error on guard clause with Caliburn.Micro

牧云@^-^@ 提交于 2019-12-07 21:15:21

问题


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:


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



来源:https://stackoverflow.com/questions/6719291/error-on-guard-clause-with-caliburn-micro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!