/// <summary>
        /// Adds a subscription to the element manipulation API of a <see cref="UIElement"/> to then
        /// be able to notify an observer of any gesture detected.
        /// </summary>
        /// <param name="observer">Observer associated to a gesture surface, to process any gesture detected.</param>
        /// <param name="gestureSurface">Surface associated with the observer in which the gesture will take place.</param>
        internal void AddObserver(IGestureRecognitionObserver observer, UIElement gestureSurface)
        {
            // Register the surface first, using the fact the observer registry (_observersOfElement) doesn't have a reference
            // to the surface.
            RegisterGestureSurface(gestureSurface);

            // Then you register the observer.
            var observers = GetObserversFor(gestureSurface);
            observers = IncludeObserver(observers, observer);
            _observersOfElement[gestureSurface] = observers;
        }
        /// <summary>
        /// Adds a subscription to the element manipulation API of a <see cref="UIElement"/> to then
        /// be able to notify an observer of any gesture detected.
        /// </summary>
        /// <param name="observer">Observer associated to a gesture surface, to process any gesture detected.</param>
        /// <param name="gestureSurface">Surface associated with the observer in which the gesture will take place.</param>
        internal void AddObserver(IGestureRecognitionObserver observer, UIElement gestureSurface)
        {
            // Register the surface first, using the fact the observer registry (_observersOfElement) doesn't have a reference
            // to the surface.
            RegisterGestureSurface(gestureSurface);

            // Then you register the observer.
            var observers = GetObserversFor(gestureSurface);

            observers = IncludeObserver(observers, observer);
            _observersOfElement[gestureSurface] = observers;
        }
        /// <summary>
        /// Drops the subscription to the gesture surface and its associated observer.
        /// </summary>
        /// <param name="observer">Observer associated to a gesture surface, to process any gesture detected.</param>
        /// <param name="gestureSurface">Surface associated with the observer in which the gesture will take place.</param>
        internal void RemoveObserver(IGestureRecognitionObserver observer, UIElement gestureSurface)
        {
            // Removing the observer from the subscriptions
            var observers = GetObserversFor(gestureSurface);

            observers.RemoveWhere(o => o == observer);
            _observersOfElement[gestureSurface] = observers;

            // If there is nobody observing the element, let's drop it.
            if (!_observersOfElement[gestureSurface].Any())
            {
                // clearing the subscriptions
                gestureSurface.ManipulationStarting  -= HandleManipulationStarting;
                gestureSurface.ManipulationCompleted -= HandleManipulationCompleted;
                gestureSurface.ManipulationDelta     -= HandleManipulationDelta;
                // removing everything else.
                _observersOfElement.Remove(gestureSurface);
            }
        }
        /// <summary>
        /// Drops the subscription to the gesture surface and its associated observer.
        /// </summary>
        /// <param name="observer">Observer associated to a gesture surface, to process any gesture detected.</param>
        /// <param name="gestureSurface">Surface associated with the observer in which the gesture will take place.</param>
        internal void RemoveObserver(IGestureRecognitionObserver observer, UIElement gestureSurface)
        {
            // Removing the observer from the subscriptions
            var observers = GetObserversFor(gestureSurface);
            observers.RemoveWhere(o => o == observer);
            _observersOfElement[gestureSurface] = observers;

            // If there is nobody observing the element, let's drop it.
            if (!_observersOfElement[gestureSurface].Any())
            {
                // clearing the subscriptions
                gestureSurface.ManipulationStarting -= HandleManipulationStarting;
                gestureSurface.ManipulationCompleted -= HandleManipulationCompleted;
                gestureSurface.ManipulationDelta -= HandleManipulationDelta;
                // removing everything else.
                _observersOfElement.Remove(gestureSurface);
            }
        }
 private static HashSet<IGestureRecognitionObserver> IncludeObserver(HashSet<IGestureRecognitionObserver> observers, IGestureRecognitionObserver observer)
 {
     observers.Add(observer);
     return observers;
 }
 private static HashSet <IGestureRecognitionObserver> IncludeObserver(HashSet <IGestureRecognitionObserver> observers, IGestureRecognitionObserver observer)
 {
     observers.Add(observer);
     return(observers);
 }