Solved

understanding   definition INotifyPropertyChanged ? (indirectly about interface)

Posted on 2010-11-14
2
457 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In C# Using WebClient method how to post certificate from file with password 3 31
Media.Imaging 1 18
Video Player 2017 5 20
Help with error when uploading excel file 3 26
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

786 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