0

I have a class Target and a static property, in another class, called points. Each time the user hits a target, I want to increase the points. The reason I put points in a different static class is so that each Target object can access it. The problem is that the textblock displaying the points exists in the MainPage and not in each Target object. Since I can't bind my XAML to a static property, how can I make it so that each Target object can somehow let the MainPage know that it should update the points textblock? thanks for any advice

Skoder
  • 3,983
  • 11
  • 46
  • 73

2 Answers2

1

You could totally apply the MVVM pattern here. If there is a static ViewModel that is bound to the main window, then you can raise a notification each time a property changes and the Views (all tied windows that display the data) will be automatially updated (re-bound).

I would recommend checking Laurent Bugnion's MVVM Light framework. It has a lot of this plumbing done for you, so all that needs to be done from your side is to put the parts together and bind them correctly.

Some resources worth checking for your situation:

If you need samples, take a look here.

Community
  • 1
  • 1
Den
  • 16,686
  • 4
  • 47
  • 87
0

Are Class Target and AnotherClass.points within the same name space? If so, may be the following helps:

/* In Window class */
Window w = new Window();

/* function where Target get hit */
w = this;
/* code to update points */
w.textbox1.Text = AnotherClass.points.ToString();
KMC
  • 19,548
  • 58
  • 164
  • 253