2012-08-09 35 views
3

我正在实现一个事件结构来将信息从View传递给Presenter。在视图中,单击一个按钮时,下面的代码被称为:调用委托时发生NotImplementedException

private void alterCmpd1() 
{ 
    EventHandler AlterEvent = AlterCompound1_Action; 
    if (AlterEvent != null) AlterEvent(this, EventArgs.Empty); 
} 

public event EventHandler AlterCompound1_Action; 

出于某种原因,一个NotImplementedException总是出现在:

AlertEvent(this, EventArgs.Empty); 

有人能帮助我弄清楚为什么?从发言类

代码:

public MainPresenter(IMainView view, IModel model) 
    { 
     this.view = view; 
     this.view.AlterCompound1_Action += new EventHandler(view_AlterCompound1); 
     this.model = model; 
     view.Show(); 
    } 

    void view_AlterCompound1(object sender, EventArgs e) 
    { 
     // I commented out this code, on the off 
     // chance that it was affecting things. Still no luck. 
    } 

回答

1

感谢威尔,我意识到我犯的错误。我一直在使用“构建解决方案”工具,但我忽略了查看Visual Studio 2010的构建配置管理器(构建 - >配置管理器)。在那里,我发现这一点:

Screenshot of configuration manager in VS2010

之前,其中的一些构建列复选标记(对应于我编辑的项目,如QAz.Presenter和QAz.View)的没有选择,那么“ Build Solution“正在跳过它们。选择这些项目后,Visual Studio知道在我运行解决方案时构建它们。

5

90%肯定,如果你看一下,你会发现这一点。

private void AlterCompound1_Action(object, EventArgs e) 
{ 
    throw new NotImplementedException(); 
} 
+0

不幸的是,没有。那会让我的生活更轻松。 – 2012-08-09 20:23:58

+0

@QtotheC:我敢打赌,如果你删除了MainPresenter类,重新编译并运行异常会以任何方式发生。尝试一下。 – Will 2012-08-09 20:39:02

+0

是的,你是对的。我认为它会抱怨在别的地方错过了一堂课。是什么造成的?这与我的代码文件在不同类中被拆分有什么关系?我在VS 2010工作,并告诉它重建解决方案。 – 2012-08-09 20:43:22