错误与Caliburn.Micro后卫条款 [英] Error on guard clause with Caliburn.Micro

查看:129
本文介绍了错误与Caliburn.Micro后卫条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现这样的后卫Caliburn.Micro处理,但我得到一个无效转换异常在应用程序运行时

I am trying to implement so guard handling with Caliburn.Micro but I am getting an invalid cast exception when the application runs.

此属性:

    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.

推荐答案

您需要做CanSaveAndNavigateToComposeView到属性,而不是方法。

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

这篇关于错误与Caliburn.Micro后卫条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆