ScrollViewerUtilities.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace HistoryDLL
  9. {
  10. public class ScrollViewerUtilities
  11. {
  12. #region HorizontalOffset
  13. /// <summary>
  14. /// HorizontalOffset Attached Dependency Property
  15. /// </summary>
  16. public static DependencyProperty HorizontalOffsetProperty =
  17. DependencyProperty.RegisterAttached("HorizontalOffset", typeof(double), typeof(ScrollViewerUtilities),
  18. new FrameworkPropertyMetadata(ScrollViewerUtilitieschange(),
  19. new PropertyChangedCallback(OnHorizontalOffsetChanged)));
  20. public static bool UseMotionStop = false;
  21. private static object ScrollViewerUtilitieschange()
  22. {
  23. double result = (double)(int.Parse(System.Windows.Application.Current.Properties["ReturnPos"].ToString()));
  24. return result;
  25. }
  26. /// <summary>
  27. /// Gets the HorizontalOffset property. This dependency property
  28. /// indicates ....
  29. /// </summary>
  30. public static double GetHorizontalOffset(DependencyObject d)
  31. {
  32. return (double)d.GetValue(HorizontalOffsetProperty);
  33. }
  34. /// <summary>
  35. /// Sets the HorizontalOffset property. This dependency property
  36. /// indicates ....
  37. /// </summary>
  38. public static void SetHorizontalOffset(DependencyObject d, double value)
  39. {
  40. d.SetValue(HorizontalOffsetProperty, value);
  41. }
  42. /// <summary>
  43. /// Handles changes to the HorizontalOffset property.
  44. /// </summary>
  45. private static void OnHorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  46. {
  47. if (!UseMotionStop)
  48. {
  49. var viewer = (ScrollViewer)d;
  50. viewer.ScrollToHorizontalOffset((double)e.NewValue);
  51. }
  52. }
  53. #endregion
  54. #region VerticalOffset
  55. /// <summary>
  56. /// VerticalOffset Attached Dependency Property
  57. /// </summary>
  58. public static readonly DependencyProperty VerticalOffsetProperty =
  59. DependencyProperty.RegisterAttached("VerticalOffset", typeof(double), typeof(ScrollViewerUtilities),
  60. new FrameworkPropertyMetadata((double)0.0,
  61. new PropertyChangedCallback(OnVerticalOffsetChanged)));
  62. /// <summary>
  63. /// Gets the VerticalOffset property. This dependency property
  64. /// indicates ....
  65. /// </summary>
  66. public static double GetVerticalOffset(DependencyObject d)
  67. {
  68. return (double)d.GetValue(VerticalOffsetProperty);
  69. }
  70. /// <summary>
  71. /// Sets the VerticalOffset property. This dependency property
  72. /// indicates ....
  73. /// </summary>
  74. public static void SetVerticalOffset(DependencyObject d, double value)
  75. {
  76. d.SetValue(VerticalOffsetProperty, value);
  77. }
  78. /// <summary>
  79. /// Handles changes to the VerticalOffset property.
  80. /// </summary>
  81. private static void OnVerticalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  82. {
  83. var viewer = (ScrollViewer)d;
  84. viewer.ScrollToVerticalOffset((double)e.NewValue);
  85. }
  86. #endregion
  87. }
  88. }