Skip to content

Instantly share code, notes, and snippets.

@mfakane
Created May 7, 2012 16:38
Show Gist options
  • Save mfakane/2628851 to your computer and use it in GitHub Desktop.
Save mfakane/2628851 to your computer and use it in GitHub Desktop.
Listen property changes using Binding
using System;
using System.Windows;
using System.Windows.Data;
namespace Linearstar.Lavis.Presentation
{
public class DependencyPropertyListener : DependencyObject
{
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(object), typeof(DependencyPropertyListener), new PropertyMetadata((sender, e) =>
{
if (e.OldValue != e.NewValue)
((DependencyPropertyListener)sender).Changed.RaiseEvent(sender, EventArgs.Empty);
}));
public event EventHandler Changed;
public object Value
{
get
{
return (object)GetValue(ValueProperty);
}
set
{
SetValue(ValueProperty, value);
}
}
public void Listen(Binding binding)
{
BindingOperations.SetBinding(this, ValueProperty, binding);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment