Field value changed best practice

Posts   
 
    
mdbruning
User
Posts: 18
Joined: 10-Mar-2008
# Posted on: 10-Mar-2008 12:51:27   

Hi all,

I was wondering what's the best practice for implemening actions on field value changes. Now I implemented it using the following code:


        protected override void OnPropertyChanged(string propertyName)
        {
            switch (propertyName)
            {
                case "ProductId":
                    this.BtwId = this.Product.BtwId;
                    break;
            }

            base.OnPropertyChanged(propertyName);
        }

Is this the proper way to do it?

Thanks in advance! Mathieu

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 10-Mar-2008 19:55:15   

thats a good way to do it, but I guess it depends of what you are trying to accomplish in the end.

mdbruning
User
Posts: 18
Joined: 10-Mar-2008
# Posted on: 12-Mar-2008 09:11:54   

what I mean is the following, there are several ways to implement action on field value changes, for example:

  • Use the PropertyChanged event
  • Use the OnPropertyChanged event handler
  • Override a property and add custom actions to it

My question is, whats the best way to implement it?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Mar-2008 09:36:48   

I'd recommend any of these (same effect): - Use the PropertyChanged event - Use the OnPropertyChanged event handler