Solved

understanding   definition INotifyPropertyChanged ? (indirectly about interface)

Posted on 2010-11-14
2
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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