Raise an event whenever a property’s value changed ?
-
Hi everybody. There is a property, it's named
ImageFullPath1
public string ImageFullPath1 {get; set; }
I'm gonna fire an event whenever its value changed. I know I can beware of changing with
INotifyPropertyChanged
, but I wanna do it with events. I don't know how I should do it. Could you please guide me? Thanks. -
Hi everybody. There is a property, it's named
ImageFullPath1
public string ImageFullPath1 {get; set; }
I'm gonna fire an event whenever its value changed. I know I can beware of changing with
INotifyPropertyChanged
, but I wanna do it with events. I don't know how I should do it. Could you please guide me? Thanks.INotifyPropertyChanged uses events and is there just for what you are asking.
I know the language. I've read a book. - _Madmatt
-
INotifyPropertyChanged uses events and is there just for what you are asking.
I know the language. I've read a book. - _Madmatt
I just hate the fact that it uses a string, however.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
I just hate the fact that it uses a string, however.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.
private string _MyProperty;
public string MyProperty {
Get { return this._MyProperty; }
Set {
If (this._MyProperty != value){
this._MyProperty = value;
this.OnMyPropertyChanged(EventArgs.Empty);
}
}
}public virtual void OnMyPropertyChanged(EventArgs e){
if (this.MyPropertyChanged != null){
this.MyPropertyChanged(this, e);
}
}public EventHandler MyPropertyChanged;
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.
private string _MyProperty;
public string MyProperty {
Get { return this._MyProperty; }
Set {
If (this._MyProperty != value){
this._MyProperty = value;
this.OnMyPropertyChanged(EventArgs.Empty);
}
}
}public virtual void OnMyPropertyChanged(EventArgs e){
if (this.MyPropertyChanged != null){
this.MyPropertyChanged(this, e);
}
}public EventHandler MyPropertyChanged;
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
I don't recall asking a question to which this was the answer.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
I don't recall asking a question to which this was the answer.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
Sorry, replied at the wrong level in the thread. My appologies
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Hi everybody. There is a property, it's named
ImageFullPath1
public string ImageFullPath1 {get; set; }
I'm gonna fire an event whenever its value changed. I know I can beware of changing with
INotifyPropertyChanged
, but I wanna do it with events. I don't know how I should do it. Could you please guide me? Thanks.Posted in reply to the wrong message earlier. Apologies. Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.
private string _MyProperty;
public string MyProperty {
Get { return this._MyProperty; }
Set {
If (this._MyProperty != value){
this._MyProperty = value;
this.OnMyPropertyChanged(EventArgs.Empty);
}
}
}public virtual void OnMyPropertyChanged(EventArgs e){
if (this.MyPropertyChanged != null){
this.MyPropertyChanged(this, e);
}
}public EventHandler MyPropertyChanged;
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Posted in reply to the wrong message earlier. Apologies. Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.
private string _MyProperty;
public string MyProperty {
Get { return this._MyProperty; }
Set {
If (this._MyProperty != value){
this._MyProperty = value;
this.OnMyPropertyChanged(EventArgs.Empty);
}
}
}public virtual void OnMyPropertyChanged(EventArgs e){
if (this.MyPropertyChanged != null){
this.MyPropertyChanged(this, e);
}
}public EventHandler MyPropertyChanged;
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
Thanks