How to disable ListBox auto scroll on mouse down and auto scrollintoview on item selected?
Hi,
The application I am building requires me to disable the listbox auto scroll function when user mouse down and drag on the edge of the listbox. Also when a partially visible listbox item is selected, the default behaviour is that the whole selected listbox item will be scrolled into view. I wish to disable that as well.
Any advices or hints will be appreciated. Thanks.
[400 byte] By [
szl] at [2008-1-8]
Ok, this is what I found to disable the listbox auto scroll function when user mouse down and drag on the edge of the listbox. First create a listbox deriving from System.Windows.Controls.ListBox. Then override the following virtual functions.
Code Snippet
protected override void OnPreviewMouseMove(MouseEventArgs e)
{
base.OnPreviewMouseMove(e);
// Disable scrollviewer auto scrolling when dragging occurs at listbox edge
e.Handled = true;
}
protected override void OnIsMouseCapturedChanged(DependencyPropertyChangedEventArgs e)
{
//Do not call the base function to disable item selection changes when dragging
//occurs at listbox edge
//base.OnIsMouseCapturedChanged(e);
}
Comments and improvements are welcome. Hope this helps.
szl at 2007-10-2 >
