Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Catching and processing mouse events

 
 
Old 04-12-2006   #1 (permalink)
Jason [Mobiform]


 
 

Catching and processing mouse events

Heres my scenario, I have a ScrollViewer with a stack panel which contains a
bunch of expanders, each expander has a ListBox with some ListItems. The
problem is that the scrollview will not respond to mouse wheel events if the
cursor is over a list item. My temporary solution is to have all ListItems
raise the mouse wheel event on the ScrollViewer when a ListItem.MouseWheel
event is triggered. This is not a good solution if I dont have total control
over the ScrollViewer contents, it works but there must be a better way...
It would be nice if I could just have a ScrollViewer.PreviewMouseWheel
capture this event and respond to it assuming nothing else has explicitly
handled that event. What is the correct procedure to do this?



My System SpecsSystem Spec
Old 04-12-2006   #2 (permalink)
Nick Kramer [MSFT]


 
 

Re: Catching and processing mouse events

Mouse wheel is supposed to scroll the thing it is over, which in your case
is the listbox. Your "temporary" solution seems like a fine solution to me,
but I'm not clear on the desired behavior. Are you trying to always
scrolled the scroll viewer no matter what? Or scroll everything inside the
scroll viewer except for list boxes? Were something else?

If you are trying to scroll the scroll viewer, I'd handle
ScrollViewer.PreviewMouseWheel and make the viewer scroll, either by calling
OnMouseWheel or by calling ScrollViewer.LineUp/Down directly.

-Nick Kramer [MSFT]

---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Jason [Mobiform]" <Jason@mobiform.com> wrote in message
news:OY3BLJlXGHA.1348@TK2MSFTNGP05.phx.gbl...
> Heres my scenario, I have a ScrollViewer with a stack panel which contains
> a bunch of expanders, each expander has a ListBox with some ListItems. The
> problem is that the scrollview will not respond to mouse wheel events if
> the cursor is over a list item. My temporary solution is to have all
> ListItems raise the mouse wheel event on the ScrollViewer when a
> ListItem.MouseWheel event is triggered. This is not a good solution if I
> dont have total control over the ScrollViewer contents, it works but there
> must be a better way... It would be nice if I could just have a
> ScrollViewer.PreviewMouseWheel capture this event and respond to it
> assuming nothing else has explicitly handled that event. What is the
> correct procedure to do this?
>



My System SpecsSystem Spec
Old 04-12-2006   #3 (permalink)
Jason


 
 

Re: Catching and processing mouse events

> Mouse wheel is supposed to scroll the thing it is over, which in your case
> is the listbox


That makes sense, I forgot that a list box would scroll given the right
conditions. However, I have set them up in such a way that they scale to the
content and should never need to scroll. I'm trying to have the scrollviewer
scroll all the time, the list boxes dont have content to scroll so I was
assuming that the list would pass off the wheel event to somewhere up the
logical tree.

I tried to override ScrollViewer.PreviewMouseWheel but I didnt see a
OnMouseWheel on the ScrollViewer, I will look again. The only option I saw
was to raise another MouseWheel event there ( RaiseEvent(e) ), which didn't
seem to work quite right ( I think I would have to create a new event and
set the source to the scrollviewer ). LineUp/Down seems like the right way
to go.

Thanks for your help,
Jason


"Nick Kramer [MSFT]" <nkramer@Microsoft.com> wrote in message
news:eh43wipXGHA.3448@TK2MSFTNGP03.phx.gbl...
> Mouse wheel is supposed to scroll the thing it is over, which in your case
> is the listbox. Your "temporary" solution seems like a fine solution to
> me, but I'm not clear on the desired behavior. Are you trying to always
> scrolled the scroll viewer no matter what? Or scroll everything inside
> the scroll viewer except for list boxes? Were something else?
>
> If you are trying to scroll the scroll viewer, I'd handle
> ScrollViewer.PreviewMouseWheel and make the viewer scroll, either by
> calling OnMouseWheel or by calling ScrollViewer.LineUp/Down directly.
>
> -Nick Kramer [MSFT]
>
> ---
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
>
> "Jason [Mobiform]" <Jason@mobiform.com> wrote in message
> news:OY3BLJlXGHA.1348@TK2MSFTNGP05.phx.gbl...
>> Heres my scenario, I have a ScrollViewer with a stack panel which
>> contains a bunch of expanders, each expander has a ListBox with some
>> ListItems. The problem is that the scrollview will not respond to mouse
>> wheel events if the cursor is over a list item. My temporary solution is
>> to have all ListItems raise the mouse wheel event on the ScrollViewer
>> when a ListItem.MouseWheel event is triggered. This is not a good
>> solution if I dont have total control over the ScrollViewer contents, it
>> works but there must be a better way... It would be nice if I could just
>> have a ScrollViewer.PreviewMouseWheel capture this event and respond to
>> it assuming nothing else has explicitly handled that event. What is the
>> correct procedure to do this?
>>

>
>



My System SpecsSystem Spec
Old 04-13-2006   #4 (permalink)
Jason [Mobiform]


 
 

Re: Catching and processing mouse events

There is no OnMouseWheel function.

After playing a bit I have found that I can call LineUp/Down but the
resulting behavior is that the scrollviewer scrolls fewer lines than normal
on fast mouse wheel movement. So to get "normal" behavior I have to guess
how mousewheel deltas translates into multiple LineUp/Down calls. Is there
possibly something else I could do to remove the guesswork?

void _MainScroller_PreviewMouseWheel(object sender,
System.Windows.Input.MouseWheelEventArgs e)
{
e.Handled = true;
if (e.Delta > 0)
{
_MainScroller.LineUp();
}
else
{
_MainScroller.LineDown();
}
}
Thanks in advance
Jason

"Nick Kramer [MSFT]" <nkramer@Microsoft.com> wrote in message
news:eh43wipXGHA.3448@TK2MSFTNGP03.phx.gbl...
> Mouse wheel is supposed to scroll the thing it is over, which in your case
> is the listbox. Your "temporary" solution seems like a fine solution to
> me, but I'm not clear on the desired behavior. Are you trying to always
> scrolled the scroll viewer no matter what? Or scroll everything inside
> the scroll viewer except for list boxes? Were something else?
>
> If you are trying to scroll the scroll viewer, I'd handle
> ScrollViewer.PreviewMouseWheel and make the viewer scroll, either by
> calling OnMouseWheel or by calling ScrollViewer.LineUp/Down directly.
>
> -Nick Kramer [MSFT]
>
> ---
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
>
> "Jason [Mobiform]" <Jason@mobiform.com> wrote in message
> news:OY3BLJlXGHA.1348@TK2MSFTNGP05.phx.gbl...
>> Heres my scenario, I have a ScrollViewer with a stack panel which
>> contains a bunch of expanders, each expander has a ListBox with some
>> ListItems. The problem is that the scrollview will not respond to mouse
>> wheel events if the cursor is over a list item. My temporary solution is
>> to have all ListItems raise the mouse wheel event on the ScrollViewer
>> when a ListItem.MouseWheel event is triggered. This is not a good
>> solution if I dont have total control over the ScrollViewer contents, it
>> works but there must be a better way... It would be nice if I could just
>> have a ScrollViewer.PreviewMouseWheel capture this event and respond to
>> it assuming nothing else has explicitly handled that event. What is the
>> correct procedure to do this?
>>

>
>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Catching the messages on the fly Live Messenger
SMO : Catching Exceptions PowerShell
Manipulating mouse events through Powershell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46