I'm playing around with events/delegates and I constantly get the following error:
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll
Additional information: Exception has been thrown by the target of an invocation.
My code is as follows:
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;
}
}
Obviously, I have code in another location to open the TestWindow object:
TestWindow testWindow = new TestWindow();
testWindow.TestEvent += this.TestMethod;
And:
private void TestMethod(object sender, EventArgs e)
{
}