HomeGuidContent.xaml.cs 3.8 KB

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