Simple question:
1) I click and hold the mouse on a ListBoxItem in a ListBox.
2) Now I drag the mouse cursor down over 开发者_如何学编程the next ListBoxItem in the listIt now selects this new item. I would like to disable this. So the user has to click an item to select it. Not just drag over it.
I have Single selection turned on.
Any ideas are greatly appreciated :)
This is mostly for the benefit of people like me who still need to know this.
The link majocha provided was the answer, although it's not implemented in a particularly nice way as far as I can see, because it has a hole around the MouseUp
event and its boolean flag. Why do that when you can just interrogate the MouseEventArgs
to find out if the button is pressed? Maybe WPF as of 2010 didn't have that capability.
So here's my code for WPF 4. You just have to handle MouseMove
on the ListBox
and say this:
private void ListBox_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
(sender as ListBox).ReleaseMouseCapture();
}
Tada!
I guess overriding OnPreviewMouseMove will do. Read this for similar problem.
精彩评论