From 8316abc300d56f876a5fe3b511dc202556ad776c Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 24 Oct 2012 23:38:06 +0400 Subject: loading data on scrolling at bottom --- Juick/Classes/DependencyPropertyListener.cs | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Juick/Classes/DependencyPropertyListener.cs (limited to 'Juick/Classes/DependencyPropertyListener.cs') diff --git a/Juick/Classes/DependencyPropertyListener.cs b/Juick/Classes/DependencyPropertyListener.cs new file mode 100644 index 0000000..693c16a --- /dev/null +++ b/Juick/Classes/DependencyPropertyListener.cs @@ -0,0 +1,52 @@ +using System; +using System.Windows; +using System.Windows.Data; + +namespace Juick.Classes +{ + public class DependencyPropertyListener + { + static int index; + + readonly DependencyProperty property; + FrameworkElement target; + public event EventHandler Changed; + + public DependencyPropertyListener() + { + property = DependencyProperty.RegisterAttached( + "DependencyPropertyListener" + DependencyPropertyListener.index++, + typeof(object), + typeof(DependencyPropertyListener), + new PropertyMetadata(null, new PropertyChangedCallback(HandleValueChanged))); + } + + public void Attach(FrameworkElement element, Binding binding) + { + if (element == null) + { + throw new ArgumentNullException("element"); + } + if (target != null) + { + throw new InvalidOperationException("Cannot attach an already attached listener"); + } + target = element; + target.SetBinding(property, binding); + } + + public void Detach() + { + target.ClearValue(property); + target = null; + } + + void HandleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + if (Changed != null) + { + Changed.Invoke(this, new BindingChangedEventArgs(e)); + } + } + } +} -- cgit v1.2.3