Created
May 7, 2012 16:38
-
-
Save mfakane/2628851 to your computer and use it in GitHub Desktop.
Listen property changes using Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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