【发布时间】:2014-09-11 18:59:19
【问题描述】:
我有一个 Winforms 应用程序,我想在其中使用 MVVM 设计模式:
我关注这个tutorial
这是一篇非常有趣的文章,但我遇到了这个问题:我的应用程序是 vb.net,我将代码 (C#) 转换为 vb.net,除了这个之外它工作正常:
C# 代码
protected void ViewModel_Validated(object sender, EventArgs e)
{
this.ViewModel.AttachedControls.ToList().ForEach(c => this.errorProvider.SetError(c.Value as Control, ""));
if (!string.IsNullOrEmpty(this.ViewModel.Error)) {
this.ViewModel.Messages.ToList().ForEach(message => {
this.errorProvider.SetError(this.ViewModel.AttachedControls[message.Key] as Control, message.Value);
});
}
}
Vb.net 代码
Protected Sub ViewModel_Validated(ByVal sender As Object, ByVal e As EventArgs)
Me.ViewModel.AttachedControls.ToList().ForEach(Function(c) Me.errorProvider.SetError(TryCast(c.Value, Control), ""))
If Not String.IsNullOrEmpty(Me.ViewModel.[Error]) Then
Me.ViewModel.Messages.ToList().ForEach(Function(message)
Me.errorProvider.SetError(TryCast(Me.ViewModel.AttachedControls(message.Key), Control), message.Value)
End Function)
End If
End Sub
问题出在这一行:
Me.ViewModel.AttachedControls.ToList().ForEach(Function(c) Me.errorProvider.SetError(TryCast(c.Value, Control), ""))
错误:
Expression does not produce a value.
我需要知道
- 这个错误的原因是什么?
- 我该如何解决?
【问题讨论】:
标签: c# .net vb.net winforms mvvm