473,473 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Implementing PropertyChanged Event Ideas

I need to implement an event to notify when a property has changed.

Method 1.
If I use a generic PropertyChanged event from System.ComponentModel then it
will be raised for every property if 1 or more properties changed events are
consumed. (more overhead, less coding)
i.e
PropertyChanged(object sender, PropertyChangedEventArgs e);

Method 2.
If I implement a PropertyNameChanged event then I have to have a delegate
and event for every property but it will only be raised if consumed on a 1
by 1 basis. (less overhead, more coding) (would not be hard to write an
addin to generate code for this).
i.e.
Property1Changed(object sender, EventArgs e)
or
Property1Changed()

If I use method 1 (which I am leaning towards at the moment) then I would be
inclined to add a string constant to the class for each property simply to
indicate the property name so I can use a switch in the consuming class to
determine which property changed and avoid typos when typing property names.

What have others done in this situation?

Cheers
JB
Nov 16 '05 #1
3 10373

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:Eu*******************@news-server.bigpond.net.au...
Method 2.
If I implement a PropertyNameChanged event then I have to have a delegate
and event for every property but it will only be raised if consumed on a 1
by 1 basis. (less overhead, more coding) (would not be hard to write an
addin to generate code for this).
i.e.
Property1Changed(object sender, EventArgs e)
or
Property1Changed()

It would appear that this is the method commonly in use judging by the
framework and third party control libraries.
Where is Method 1 applicable then?
Nov 16 '05 #2
I just wrote an article that discusses meta-properties and property change
notification.

http://weblogs.asp.net/justin_rogers...26/120201.aspx

You'll find that I went with the concept of a storage container that fires a
single event
whenever any property changes, is removed, or added. Having a *Changed event
on a per property basis is a real PITA and does nothing more than increase the
size
of your control library.

Also note there are security issues with having events defined using the
standard
EventHandler. Various luring attacks can take advantage of the generic
signature
to run code using your privs rather than the privs of the code that attached the
handler. This is pretty sneaky, but it can happen.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:_2******************@news-server.bigpond.net.au...

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:Eu*******************@news-server.bigpond.net.au...
Method 2.
If I implement a PropertyNameChanged event then I have to have a delegate
and event for every property but it will only be raised if consumed on a 1
by 1 basis. (less overhead, more coding) (would not be hard to write an
addin to generate code for this).
i.e.
Property1Changed(object sender, EventArgs e)
or
Property1Changed()

It would appear that this is the method commonly in use judging by the
framework and third party control libraries.
Where is Method 1 applicable then?

Nov 16 '05 #3

"John Baro" <jo***@NOSPAMmesware.com.au> schrieb im Newsbeitrag
news:Eu*******************@news-server.bigpond.net.au...
I need to implement an event to notify when a property has changed.

Method 1.
If I use a generic PropertyChanged event from System.ComponentModel then it will be raised for every property if 1 or more properties changed events are consumed. (more overhead, less coding)
i.e
PropertyChanged(object sender, PropertyChangedEventArgs e);

Method 2.
If I implement a PropertyNameChanged event then I have to have a delegate
and event for every property but it will only be raised if consumed on a 1
by 1 basis. (less overhead, more coding) (would not be hard to write an
addin to generate code for this).
i.e.
Property1Changed(object sender, EventArgs e)
or
Property1Changed()

If I use method 1 (which I am leaning towards at the moment) then I would be inclined to add a string constant to the class for each property simply to
indicate the property name so I can use a switch in the consuming class to
determine which property changed and avoid typos when typing property names.
What have others done in this situation?

You can use MethodBase.GetCurrentMethod() to determine the name of the
property which fired the event.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: cppaddict | last post by:
I have a design question which I am posting here because the implementation will be in C++ and I think there may be C++ specific language constructs (eg, friends) that might be relevant to the...
0
by: Joshua Belden | last post by:
I have a class that is marked as Serializable that implements INotifyPropertyChanged. private event PropertyChangedEventHandler _PropertyChanged; public event PropertyChangedEventHandler...
5
by: Mark | last post by:
Hi. I searched for hours now but can't find how to get the following to work: A usercontrol with two properties (A and B). If A is changed in the designer, B should be changed as well. This...
1
by: Gokul | last post by:
Hi, I'm using indexed properties in an object which acts as the binding source. How can I implement INotifyPropertyChanged for that object so that when the indexed property is updated, binding...
5
by: Not Me | last post by:
Hi there, There are hundreds of messages with different solutions on how to limit the number of characters for a text box in ASP.net, none of which I can get to work!! I do lie, because using...
0
by: ZA_AJR | last post by:
Hi All I have a class (aClass, derived from aBaseClass) with implements an interface IMyInterface. aClass also has a private member of type aNotherClass which raises various events. I would like...
4
by: Mohamed Mansour | last post by:
Hello, What is the purpose of implementing the Observer Pattern if we can trigger an event easily? For example (from books), You have a "Forecaster" which notifies "Observable" when a...
2
by: Dinsdale | last post by:
We have created a object library that implements the INotifyPropertyChanged.PropertyChanged to bubble changes up to higher level classes. For instance, we have a person class that can have...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.