Solved

understanding   definition INotifyPropertyChanged ? (indirectly about interface)

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net, radiobuttonlist, c# 3 66
aspx ascx, c# 7 38
Open telerik datetime picker programmatically 13 40
Easiest intro into .NET CORE? 2 30
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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