summaryrefslogtreecommitdiff
path: root/Juick/Classes/DependencyPropertyListener.cs
diff options
context:
space:
mode:
authorGravatar Konstantin2012-10-24 23:38:06 +0400
committerGravatar Konstantin2012-10-24 23:38:06 +0400
commit8316abc300d56f876a5fe3b511dc202556ad776c (patch)
tree765788affac60e3819993e7f9803ba14070034ff /Juick/Classes/DependencyPropertyListener.cs
parent61d3230b053453c9f8e145341a3def0d1ad8ff32 (diff)
loading data on scrolling at bottom
Diffstat (limited to 'Juick/Classes/DependencyPropertyListener.cs')
-rw-r--r--Juick/Classes/DependencyPropertyListener.cs52
1 files changed, 52 insertions, 0 deletions
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<BindingChangedEventArgs> 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));
+ }
+ }
+ }
+}