using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace HistoryDLL
{
    public class ScrollViewerUtilities
    {
        #region HorizontalOffset

        /// <summary>
        /// HorizontalOffset Attached Dependency Property
        /// </summary>
        public static DependencyProperty HorizontalOffsetProperty =
            DependencyProperty.RegisterAttached("HorizontalOffset", typeof(double), typeof(ScrollViewerUtilities),
                new FrameworkPropertyMetadata(ScrollViewerUtilitieschange(),
                    new PropertyChangedCallback(OnHorizontalOffsetChanged)));

        public static bool UseMotionStop = false;

        private static object ScrollViewerUtilitieschange()
        {
            double result = (double)(int.Parse(System.Windows.Application.Current.Properties["ReturnPos"].ToString()));

            return result;
        }

        /// <summary>
        /// Gets the HorizontalOffset property.  This dependency property 
        /// indicates ....
        /// </summary>
        public static double GetHorizontalOffset(DependencyObject d)
        {
            return (double)d.GetValue(HorizontalOffsetProperty);
        }

        /// <summary>
        /// Sets the HorizontalOffset property.  This dependency property 
        /// indicates ....
        /// </summary>
        public static void SetHorizontalOffset(DependencyObject d, double value)
        {
            d.SetValue(HorizontalOffsetProperty, value);
        }

        /// <summary>
        /// Handles changes to the HorizontalOffset property.
        /// </summary>
        private static void OnHorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!UseMotionStop)
            {
                var viewer = (ScrollViewer)d;
                viewer.ScrollToHorizontalOffset((double)e.NewValue);
            }
        }

        #endregion

        #region VerticalOffset

        /// <summary>
        /// VerticalOffset Attached Dependency Property
        /// </summary>
        public static readonly DependencyProperty VerticalOffsetProperty =
            DependencyProperty.RegisterAttached("VerticalOffset", typeof(double), typeof(ScrollViewerUtilities),
                new FrameworkPropertyMetadata((double)0.0,
                    new PropertyChangedCallback(OnVerticalOffsetChanged)));

        /// <summary>
        /// Gets the VerticalOffset property.  This dependency property 
        /// indicates ....
        /// </summary>
        public static double GetVerticalOffset(DependencyObject d)
        {
            return (double)d.GetValue(VerticalOffsetProperty);
        }

        /// <summary>
        /// Sets the VerticalOffset property.  This dependency property 
        /// indicates ....
        /// </summary>
        public static void SetVerticalOffset(DependencyObject d, double value)
        {
            d.SetValue(VerticalOffsetProperty, value);
        }

        /// <summary>
        /// Handles changes to the VerticalOffset property.
        /// </summary>
        private static void OnVerticalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var viewer = (ScrollViewer)d;
            viewer.ScrollToVerticalOffset((double)e.NewValue);
        }

        #endregion
    }
}
