Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is PropertyChangedEventHandler used?

Tags:

c#

linq

events

How is PropertyChangedEventHandler used? Can you tell me what this bit of code in a class' Initalize method does? There is a class in the project we are working on that has a private Initialize method. And there is a bit of code in this method that I want to discuss.
But first, let me describe the class. The class is defined as something like this: public class Skoobie : BaseThingy, ISkoobie

So, that means that the class, “Skoobie” has two parents that it is inheriting from. What are all the implications about this?

Anyway, so the Initalize method is something like this:

private void Initialize()
{
            this.PropertyChanged += (o, e) =>
                {
                     If (e != null)
                     {
                        // some stuff is done
                     }

                };
}

Now, “PropertyCHanged” is a member of the parent class “BaseThingy” which is defined like this:

public event PropertyChangedEventHandler PropertyChanged; What is the code this.PropertyChanged += (o, e) =>... all about? Is it a LINQ thingy?

like image 864
xarzu Avatar asked Mar 17 '26 10:03

xarzu


1 Answers

This is a lambda expression ( http://msdn.microsoft.com/en-us/library/bb397687.aspx ) that is being added to the PropertyChanged event.
This event is defined in the INotifyPropertyChanged Interface : http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx
This event is fundamental to things like Databinding in WPF / Silverlight . You would use it yourself for setting a data object as dirty. Hope this helps.

Also for public class Skoobie : BaseThingy, ISkoobie C# does not have multiple inheritance. You can however implement multiple Interfaces (in your case ISkoobie is an interface and BaseThingy is the base class)

like image 198
basarat Avatar answered Mar 19 '26 01:03

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!