mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-22 08:02:24 +08:00
59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
|
using System.Windows;
|
|||
|
using System.Windows.Controls;
|
|||
|
using System.Windows.Input;
|
|||
|
|
|||
|
namespace PowerLauncher
|
|||
|
{
|
|||
|
public partial class ResultListBox
|
|||
|
{
|
|||
|
protected object _lock = new object();
|
|||
|
private Point _lastpos;
|
|||
|
private ListBoxItem curItem = null;
|
|||
|
public ResultListBox()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|||
|
{
|
|||
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
|
|||
|
{
|
|||
|
ScrollIntoView(e.AddedItems[0]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnMouseEnter(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
lock(_lock)
|
|||
|
{
|
|||
|
curItem = (ListBoxItem)sender;
|
|||
|
var p = e.GetPosition((IInputElement)sender);
|
|||
|
_lastpos = p;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnMouseMove(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
lock(_lock)
|
|||
|
{
|
|||
|
var p = e.GetPosition((IInputElement)sender);
|
|||
|
if (_lastpos != p)
|
|||
|
{
|
|||
|
((ListBoxItem)sender).IsSelected = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ListBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|||
|
{
|
|||
|
lock(_lock)
|
|||
|
{
|
|||
|
if (curItem != null)
|
|||
|
{
|
|||
|
curItem.IsSelected = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|