Caliburn.Micro的保护条款出错

dea*_*vmc 2 c# mvvm windows-phone-7 caliburn.micro

我正在尝试使用Caliburn.Micro实现这样的防护处理,但是当应用程序运行时,我得到了一个无效的强制转换异常.

财产:

    public Account UserAccount
    {
        get
        {
            return account;
        }
        set
        {
                account = value;
                NotifyOfPropertyChange(() => UserAccount);
                NotifyOfPropertyChange(() => CanSaveAndNavigateToComposeView());
        }
    }
Run Code Online (Sandbox Code Playgroud)

方法:

    public void SaveAndNavigateToComposeView()
    {
        CommitAccountToStorage();
        navigationService.UriFor<ComposeViewModel>().Navigate();
    }
Run Code Online (Sandbox Code Playgroud)

守卫:

    public bool CanSaveAndNavigateToComposeView()
    {
        return !(string.IsNullOrEmpty(UserAccount.DisplayName) ||
                 string.IsNullOrEmpty(UserAccount.Username)    ||
                 string.IsNullOrEmpty(UserAccount.Password)    || 
                 string.IsNullOrEmpty(UserAccount.ServerSymbol));
    }
Run Code Online (Sandbox Code Playgroud)

如果我取消对财产的通知道具更改,那么警卫就可以工作,但这意味着我的方法永远无法评估.

Eis*_*ect 6

您需要将CanSaveAndNavigateToComposeView转换为属性而不是方法.