ScrollUtil.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. using System.Windows.Media;
  9. namespace GeekDesk.Util
  10. {
  11. public class ScrollUtil
  12. {
  13. public static bool IsBootomScrollView(ScrollViewer view)
  14. {
  15. try
  16. {
  17. bool isBottom = false;
  18. double dVer = view.VerticalOffset;
  19. double vViewport = view.ViewportHeight;
  20. double eextent = view.ExtentHeight;
  21. if (dVer + vViewport >= eextent)
  22. {
  23. isBottom = true;
  24. }
  25. else
  26. {
  27. isBottom = false;
  28. }
  29. return isBottom;
  30. } catch (Exception e)
  31. {
  32. return false;
  33. }
  34. }
  35. public static bool IsTopScrollView(ScrollViewer view)
  36. {
  37. try
  38. {
  39. return (int)view.VerticalOffset == 0;
  40. }
  41. catch (Exception e)
  42. {
  43. return false;
  44. }
  45. }
  46. public static T FindSimpleVisualChild<T>(DependencyObject element) where T : class
  47. {
  48. try
  49. {
  50. while (element != null)
  51. {
  52. if (element is T)
  53. return element as T;
  54. if (VisualTreeHelper.GetChildrenCount(element) > 0)
  55. {
  56. element = VisualTreeHelper.GetChild(element, 0);
  57. }
  58. }
  59. return null;
  60. }
  61. catch (Exception e)
  62. {
  63. return null;
  64. }
  65. }
  66. }
  67. }