I’m writing a website in Silverlight 5 right now. I have a public static class set up, and in that class I have a public static int defined. In the MainPage class (which is a public partial class), I want to capture an event when the public static int is changed. Is there any way I could set up an event to do this for me, or is there another way I would be able to get the same behaviour? (Or is what I am trying to do even possible?)
Share
To elaborate on what Hans said, you can use properties instead of fields
Fields:
Properties:
Use properties just as you would regular fields. When coding them, the
valuekeyword is automatically passed to the set accessor and is the value the variable is being set to. For example,Foo.Bar = 100Would pass
100, sovaluewould be100.Properties on their own do not store values unless they are auto-implemented, in which case you wouldn’t be able to define a body for the accessors (get and set). This is why we use a private variable,
bar, to store the actual integer value.edit: Actually, msdn has a much nicer example:
http://msdn.microsoft.com/en-us/library/ms743695.aspx