Solved

understanding   definition INotifyPropertyChanged ? (indirectly about interface)

Posted on 2010-11-14
2
452 Views
Last Modified: 2013-12-17

INotifyPropertyChanged : Notifies clients that a property value has changed.

My question

1) Who is Client

2)  Who is Service Provider.
 
  In general interface acts like this right      Client =====>  Interface  <===== Service Provider.

But who is client here and who is service provider.

Can any one explain with sample code.  Good if it is console  program

Thankoyu




0
Comment
Question by:N_Sri
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34131948
The client is any object that subscribes to the event exposed by the interface (i.e the object that needs to know the property has changed)
The service provider is the object that implements the interface and wants to tell subscribers when one of its properties has changed.

In the following sample the Console application is the client:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            ServiceProvider dummy = new ServiceProvider();
            dummy.PropertyChanged += SomethingChanged;

            dummy.Name = "Wibble";

            Console.ReadLine();
        }

        static void SomethingChanged(object sender, PropertyChangedEventArgs e)
        {
            Console.WriteLine("Woohoo! The {0} property changed", e.PropertyName);
        }
    }

    class ServiceProvider : INotifyPropertyChanged
    {
        // INotifyPropertyChanged implementation
        public event PropertyChangedEventHandler PropertyChanged;

        public string Name 
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private string _name;
    }
}

Open in new window

0
 

Author Closing Comment

by:N_Sri
ID: 34132163
Thankyou
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now