Exemplo n.º 1
0
        /// <summary>
        /// Handles changes to the ScrollEventListeners DependencyProperty.
        /// </summary>
        /// <param name="o">DependencyObject that changed.</param>
        /// <param name="e">Event data for the DependencyPropertyChangedEvent.</param>
        private static void OnScrollEventListenersChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement el = o as FrameworkElement;

            if (null != el)
            {
                el.Loaded +=
                    (s, e2) =>
                {
                    var element = FindChild <ScrollViewer>(o);
                    if (null != element)
                    {
                        ScrollEventListenerCollection oldListeners = e.OldValue as ScrollEventListenerCollection;
                        ScrollEventListenerCollection newListeners = e.NewValue as ScrollEventListenerCollection;
                        if (null != oldListeners)
                        {
                            oldListeners.Target = null;
                        }
                        if (null != newListeners)
                        {
                            newListeners.Target = element;
                        }
                    }
                };
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets a ScrollEventListener property for the provided DependencyObject, creates a new one if necessary.
 /// </summary>
 /// <param name="obj">The DependencyObject whose ScrollEventListener you would like to get.</param>
 /// <returns>The ScrollEventListener associated with the provided DependencyObject</returns>
 public static ScrollEventListenerCollection GetScrollEventListeners(DependencyObject obj)
 {
     if (null == obj)
     {
         throw new ArgumentNullException("obj");
     }
     else
     {
         ScrollEventListenerCollection listeners =
             (obj.GetValue(ScrollEventListenersProperty) as ScrollEventListenerCollection) ?? new ScrollEventListenerCollection();
         obj.SetValue(ScrollEventListenersProperty, listeners);
         return(listeners);
     }
 }