Solved

understanding   definition INotifyPropertyChanged ? (indirectly about interface)

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now