HomeGuidContent.xaml.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. using System.Windows.Media;
  5. namespace PDF_Master.Views.HomePanel
  6. {
  7. /// <summary>
  8. /// HomeGuidContent.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class HomeGuidContent : UserControl
  11. {
  12. public HomeGuidContent()
  13. {
  14. InitializeComponent();
  15. }
  16. private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  17. {
  18. e.Handled = true;
  19. var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
  20. {
  21. RoutedEvent = UIElement.MouseWheelEvent,
  22. Source = sender
  23. };
  24. var listView = FindChild<ListView>(sender as DependencyObject);
  25. listView.RaiseEvent(eventArg);
  26. }
  27. private static T FindChild<T>(DependencyObject parent) where T : DependencyObject
  28. {
  29. if (parent == null) return null;
  30. var foundChild = default(T);
  31. var childCount = VisualTreeHelper.GetChildrenCount(parent);
  32. for (var i = 0; i < childCount; i++)
  33. {
  34. var child = VisualTreeHelper.GetChild(parent, i);
  35. if (child is T t)
  36. {
  37. foundChild = t;
  38. break;
  39. }
  40. foundChild = FindChild<T>(child);
  41. if (foundChild != null) break;
  42. }
  43. return foundChild;
  44. }
  45. }
  46. }