From 1ab636a4f1b956b1213e30b84cd6de133ebcb2ef Mon Sep 17 00:00:00 2001 From: KallistiMan Date: Fri, 22 Feb 2019 20:36:21 +0100 Subject: [PATCH] fix unexpected hovor without mouse moving (#2368) fix #975 close #2043 --- Wox/ResultListBox.xaml | 6 ++++-- Wox/ResultListBox.xaml.cs | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Wox/ResultListBox.xaml b/Wox/ResultListBox.xaml index ad6a22e877..cad02d5198 100644 --- a/Wox/ResultListBox.xaml +++ b/Wox/ResultListBox.xaml @@ -16,7 +16,8 @@ KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" SelectionChanged="OnSelectionChanged" - IsSynchronizedWithCurrentItem="True"> + IsSynchronizedWithCurrentItem="True" + PreviewMouseDown="ListBox_PreviewMouseDown"> @@ -65,6 +66,7 @@ - \ No newline at end of file + diff --git a/Wox/ResultListBox.xaml.cs b/Wox/ResultListBox.xaml.cs index ce6de8afb4..d448d02ca9 100644 --- a/Wox/ResultListBox.xaml.cs +++ b/Wox/ResultListBox.xaml.cs @@ -1,4 +1,5 @@ using System.Runtime.Remoting.Contexts; +using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -7,6 +8,8 @@ namespace Wox [Synchronization] public partial class ResultListBox { + private Point _lastpos; + private ListBoxItem curItem = null; public ResultListBox() { InitializeComponent(); @@ -22,7 +25,26 @@ namespace Wox private void OnMouseEnter(object sender, MouseEventArgs e) { - ((ListBoxItem) sender).IsSelected = true; + curItem = (ListBoxItem)sender; + var p = e.GetPosition((IInputElement)sender); + _lastpos = p; + } + + private void OnMouseMove(object sender, MouseEventArgs e) + { + var p = e.GetPosition((IInputElement)sender); + if (_lastpos != p) + { + ((ListBoxItem) sender).IsSelected = true; + } + } + + private void ListBox_PreviewMouseDown(object sender, MouseButtonEventArgs e) + { + if (curItem != null) + { + curItem.IsSelected = true; + } } } -} \ No newline at end of file +}