【发布时间】:2013-12-27 04:37:07
【问题描述】:
我正在玩活动/代表,但我经常收到以下错误:
“System.Reflection.TargetInvocationException”类型的未处理异常发生在 PresentationFramework.dll
附加信息:调用的目标已抛出异常。
我的代码如下:
namespace Test
{
using System;
using System.Windows;
public partial class TestWindow : Window
{
public TestWindow()
{
this.InitializeComponent();
this.TestEvent(this, new EventArgs());
}
public delegate void TestDelegate(object sender, EventArgs e);
public event TestDelegate TestEvent;
}
}
显然,我在另一个位置有代码可以打开 TestWindow 对象:
TestWindow testWindow = new TestWindow();
testWindow.TestEvent += this.TestMethod;
还有:
private void TestMethod(object sender, EventArgs e)
{
}
【问题讨论】:
标签: c# wpf events delegates targetinvocationexception