Caliburn.Micro 的保护子句出错
我正在尝试使用 Caliburn.Micro 实现如此保护处理,但在应用程序运行时出现无效的强制转换异常。
属性:
public Account UserAccount
{
get
{
return account;
}
set
{
account = value;
NotifyOfPropertyChange(() => UserAccount);
NotifyOfPropertyChange(() => CanSaveAndNavigateToComposeView());
}
}
方法:
public void SaveAndNavigateToComposeView()
{
CommitAccountToStorage();
navigationService.UriFor<ComposeViewModel>().Navigate();
}
守卫:
public bool CanSaveAndNavigateToComposeView()
{
return !(string.IsNullOrEmpty(UserAccount.DisplayName) ||
string.IsNullOrEmpty(UserAccount.Username) ||
string.IsNullOrEmpty(UserAccount.Password) ||
string.IsNullOrEmpty(UserAccount.ServerSymbol));
}
如果我取出属性上的通知属性更改,守卫就会起作用,但这意味着我的方法永远不会评估。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 CanSaveAndNavigateToComposeView 设为属性而不是方法。
You need to make CanSaveAndNavigateToComposeView into a property rather than a method.