HomeGuidContent.xaml.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using PDF_Master.Views.HomePanel.RecentFiles;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. namespace PDF_Master.Views.HomePanel
  7. {
  8. /// <summary>
  9. /// HomeGuidContent.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class HomeGuidContent : UserControl
  12. {
  13. public HomeGuidContent()
  14. {
  15. InitializeComponent();
  16. }
  17. private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  18. {
  19. e.Handled = true;
  20. var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
  21. {
  22. RoutedEvent = UIElement.MouseWheelEvent,
  23. Source = sender
  24. };
  25. var listView = FindChild<ListView>(sender as DependencyObject);
  26. listView.RaiseEvent(eventArg);
  27. }
  28. private static T FindChild<T>(DependencyObject parent) where T : DependencyObject
  29. {
  30. if (parent == null) return null;
  31. var foundChild = default(T);
  32. var childCount = VisualTreeHelper.GetChildrenCount(parent);
  33. for (var i = 0; i < childCount; i++)
  34. {
  35. var child = VisualTreeHelper.GetChild(parent, i);
  36. if (child is T t)
  37. {
  38. foundChild = t;
  39. break;
  40. }
  41. foundChild = FindChild<T>(child);
  42. if (foundChild != null) break;
  43. }
  44. return foundChild;
  45. }
  46. private void Recentlist_MouseDown(object sender, MouseButtonEventArgs e)
  47. {
  48. //Windows:最近文件列表补充点击空白处取消选中;移除Esc取消选中逻辑
  49. if (sender is RecentFilesContent recentFilesContent)
  50. {
  51. if (recentFilesContent.GridRecentFilesList.Visibility == Visibility.Visible)
  52. {
  53. var point = e.GetPosition(recentFilesContent.GridRecentFilesList);
  54. var result = VisualTreeHelper.HitTest(recentFilesContent.GridRecentFilesList, point);
  55. if (result != null)
  56. {
  57. if (recentFilesContent.GridRecentFilesList.SelectedIndex != -1)
  58. {
  59. recentFilesContent.GridRecentFilesList.SelectedIndex = -1;
  60. }
  61. }
  62. }
  63. else if (recentFilesContent.RecentFilesList.Visibility == Visibility.Visible)
  64. {
  65. var point = e.GetPosition(recentFilesContent.RecentFilesList);
  66. var result = VisualTreeHelper.HitTest(recentFilesContent.RecentFilesList, point);
  67. if (result != null)
  68. {
  69. if (recentFilesContent.RecentFilesList.SelectedIndex != -1)
  70. {
  71. recentFilesContent.RecentFilesList.SelectedIndex = -1;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }