Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/4f55e5ee8a60b403307a to your computer and use it in GitHub Desktop.
Save Fhernd/4f55e5ee8a60b403307a to your computer and use it in GitHub Desktop.
Demostración de de uso de la interfaz INotifyPropertyChanged.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
public class UsoINotifyPropertyChanged : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate{};
public void InvocarAlCambioPropiedad([CallerMemberName] string nombrePropiedad = null)
{
PropertyChanged(this, new PropertyChangedEventArgs(nombrePropiedad));
Console.WriteLine(nombrePropiedad);
}
string nombreCliente;
public String NombreCliente
{
get
{
return nombreCliente;
}
set
{
if (value == nombreCliente) return;
nombreCliente = value;
InvocarAlCambioPropiedad(); // El compilador convierte esta
// llamada en InvocarAlCambioPropiedad("NombreCliente");
}
}
int idClient;
public int IDCliente
{
get
{
return idClient;
}
set
{
if (value == idClient) return;
idClient = value;
InvocarAlCambioPropiedad(); // El compilador convierte esta
// llamada en InvocarAlCambioPropiedad("IDCliente");
}
}
}
public class Prueba
{
public static void Main()
{
Console.WriteLine(Environment.NewLine);
UsoINotifyPropertyChanged var = new UsoINotifyPropertyChanged();
var.NombreCliente = "Julio";
var.IDCliente = 951753852;
Console.WriteLine(Environment.NewLine);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment