OnPropertyChanged
needs to be defined in the scope that you wish to update properties on.
For that to work you'll have to implement the interface INotifyPropertyChanged
.
And finally you have to provide the correct argument to the OnPropertyChanged
method. In this example "Stopped"
public struct FBarWidth : INotifyPropertyChanged
{
private int _Stopped;
public int Stopped
{
get { return _Stopped; }
set
{
_Stopped = value;
OnPropertyChanged("Stopped");
}
}
private int _Running;
//And more variables
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Edit: In your comment you mentioned that you've got a class sorounding the code you provided in your example.
That means you've nested a struct inside a class.
Just because you've nested your struct, doesn't mean it inherits properties and methods from the outer class. You still need to implement INotifyPropertyChanged
inside your struct and define the OnPropertyChanged
method inside it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…