So I have a program in which I am telling the user whether two skeletons match, but the thing is that I need to access the label via a class. The error I keep getting is
Error1 An object reference is required for the
non-static field, method, or property
'WpfApplication1.MainWindow.matchLabel'
Here’s what I have in my code:
The static Label
static Label matching
{
get { return matchLabel; } //errors here
set { matchLabel = value; } //and here
}
The Class
private class Scan
{
private void Start()
{
Skeleton skeleton = new Skeleton();
if (PersonDetected == true)
{
int SkeletonID2 = skeleton.TrackingId;
if (SkeletonID1 == SkeletonID2)
{
matching.Content = "Your IDs are Matching!";
}
else if (SkeletonID2 != SkeletonID1)
{
matching.Content = "Your IDs don't Match.";
}
}
}
private void Stop()
{
if (PersonDetected == true)
{
matching.Content = "Scan Aborted";
}
}
}
Basically I want to know how to make the label in wpf static, or if there is another way to do this.
Thanks in advance
I think that you could use another approach, like @Daniel said, using UI elements on multiple threads is a bad idea.
If my understanding is correct, you just want to notify to the user the result from your domain logic, the way I would do it is simple, create an event:
public event Action<string> MyEvent = delegate { };In your WPF view
this.MydomainComponent.MyEvent += (x) => { this.matchLabel.Content = x; };