1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using PDF_Master.Helper;
- using PDF_Master.Views.HomePanel.RecentFiles;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace PDF_Master.Views.HomePanel
- {
- /// <summary>
- /// HomeGuidContent.xaml 的交互逻辑
- /// </summary>
- public partial class HomeGuidContent : UserControl
- {
- public HomeGuidContent()
- {
- InitializeComponent();
- }
- private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
- {
- e.Handled = true;
- var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
- {
- RoutedEvent = UIElement.MouseWheelEvent,
- Source = sender
- };
- var listView = FindChild<ListView>(sender as DependencyObject);
- listView.RaiseEvent(eventArg);
- }
- private static T FindChild<T>(DependencyObject parent) where T : DependencyObject
- {
- if (parent == null) return null;
- var foundChild = default(T);
- var childCount = VisualTreeHelper.GetChildrenCount(parent);
- for (var i = 0; i < childCount; i++)
- {
- var child = VisualTreeHelper.GetChild(parent, i);
- if (child is T t)
- {
- foundChild = t;
- break;
- }
- foundChild = FindChild<T>(child);
- if (foundChild != null) break;
- }
- return foundChild;
- }
- private void Recentlist_MouseDown(object sender, MouseButtonEventArgs e)
- {
- //Windows:最近文件列表补充点击空白处取消选中;移除Esc取消选中逻辑
- // 文件列表,需要点击其他空白区域取消文件选中
- if (e.ClickCount == 1 && e.LeftButton == MouseButtonState.Pressed && Recentlist.GridRecentFilesList.Visibility == Visibility.Visible && Recentlist.GridRecentFilesList.SelectedItems.Count > 0)
- {
- HitTestResult hitTestResult = VisualTreeHelper.HitTest(Recentlist.GridRecentFilesList, e.GetPosition(Recentlist.GridRecentFilesList));
- if (hitTestResult == null)
- {
- Recentlist.GridRecentFilesList.SelectedItems.Clear();
- }
- else if (hitTestResult.VisualHit == Recentlist.GridRecentFilesList)
- {
- Recentlist.GridRecentFilesList.SelectedItems.Clear();
- }
- else if (hitTestResult.VisualHit is ScrollViewer scrollViewer)
- {
- Recentlist.GridRecentFilesList.SelectedItems.Clear();
- }
- }
- else if (e.ClickCount == 1 && e.LeftButton == MouseButtonState.Pressed && Recentlist.RecentFilesList.Visibility == Visibility.Visible && Recentlist.RecentFilesList.SelectedItems.Count > 0)
- {
- HitTestResult hitTestResult = VisualTreeHelper.HitTest(Recentlist.RecentFilesList, e.GetPosition(Recentlist.RecentFilesList));
- if (hitTestResult == null)
- {
- Recentlist.RecentFilesList.SelectedItems.Clear();
- }
- else if (hitTestResult.VisualHit == Recentlist.RecentFilesList)
- {
- Recentlist.RecentFilesList.SelectedItems.Clear();
- }
- else if (hitTestResult.VisualHit is ScrollViewer scrollViewer)
- {
- Recentlist.RecentFilesList.SelectedItems.Clear();
- }
- }
- }
- private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
- {
- Recentlist_MouseDown(sender, e);
- }
- }
- }
|