I am trying to make a simple app in WPF, and i've run into a bit of an anomaly. I have 2 classes: a partial class (for the WPF Window), and another public class I have set up myself. When I try to access the class I created from the WPF window class, I run into a TargetInvocationException telling me the object reference is not set to an instance of an object. However, the object reference that results in the exception is set to an instance of an object.
Here's my code:
public partial class MainWindow : Window
{
CurrentParent CP = new CurrentParent();
public MainWindow()
{
InitializeComponent();
CP.Par.Add("MainCanvas");
}
}
public class CurrentParent
{
private List<string> _Par;
public List<string> Par
{
get { return _Par; }
set { _Par = value; }
}
}
Of course, this is in one namespace. I cannot see any reason why I should be getting this error, as my object reference CP clearly is an instance of CurrentParent.
Would anybody have any idea of how to fix this? Thanks in advance!
-Ian