This question is in reference to another question, mine is similar but I am asking for help beyond what I have read in this answer:
Raise an event whenever a property's value changed?
EDIT: What I am trying to accomplish is a global message "service" within the application such that I can write to the message variable from different places within the application and have the User Interface (winform) pick up on the fact that there was some change to that variable and based upon the event, I can read the message variable and display its content to the user. I hope this makes more sense now.
First, I am new to the world of C# and while I understand the code written as the most accepted answer, where I fail, is to understand the final implementation. If I place this code in a .cs file and I use the namespace in winform file how do I finalize the implementation? In my case, I would want to implement the class in the winform file so I can watch for an event to occur. Once the event occurred I would write some information to the user via the winform interface. I think I would need to use the "get" of the string...but not sure how the implementation would go? I apologize in advance if this doesn't make sense, I am trying to piece this all together. Thanks for any help on this!
For reference, I have start with the answer provide and altered it for my purposes:
public class Messaging : INotifyPropertyChanged
{
private string dLMessage;
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, e);
}
protected void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
public string DLMessage
{
get { return dLMessage; }
set
{
if (value != dLMessage)
{
dLMessage = value;
OnPropertyChanged("DLMessage");
OnDLMessageChanged(EventArgs.Empty);
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnDLMessageChanged(EventArgs e)
{
EventHandler handler = DLMessageChanged;
if (handler != null)
handler(this, e);
}
public event EventHandler DLMessageChanged;
}