Nigel Page

I have implemented a zoom feature on a Frame using a ScaleTransform, which works really well except for one issue. In order to be able to scroll the contents of the Frame, it is wrapped in a ScrollViewer, except that the scroll viewer only catches the wheel mouse events when the cursor is within the hit test area for the ScrollViewer itself(just the scroll bars). The desired behaviour is that the contents will scroll whenever the wheel mouse is scrolled whilst the cursor is within the hit test area for the Frame. Any advice on how to achieve this would be greatly appreciated:-)

Re: Windows Presentation Foundation (WPF) Scrolling the contents of a Frame using an external ScrollViewer

Ben Carter - MSFT

Does the content of the Frame handle any mouse messages It's possible that something is handling the mouse message that contains the scroll wheel information.

Ben






Re: Windows Presentation Foundation (WPF) Scrolling the contents of a Frame using an external ScrollViewer

Nigel Page

Ben,

Unfortunately it's not possible to tell as the content of the Frame is dynamically generated using a TypeOf structure, from which an instance of the required object is created and navigated to. Neither I nor the app have any knowledge of the contents of the Frame.





Re: Windows Presentation Foundation (WPF) Scrolling the contents of a Frame using an external ScrollViewer

Nigel Page

Okay, a bit more exploration reveals a slightly different story...

If the Frame contains a number of controls, leaving some of the background still visible, then positioning the mouse over the background does allow scrolling. This is good behaviour. If, however, you have single control taking up the entire space (in my case this is a ListView), then there is no background available to position the mouse on and the window does not scroll. This is also fine, except that the ListView doesn't scroll either and I would have expected it to! If I remove the ScrollViewer encapsulating the Frame, then the ListView scrolls! This is annoying behaviour, because it seems that I have to know whether there is going to be any blank space on the Page in order to know whether or not I need to wrap the Frame in a ScrollViewer and that I can't do (I don't think).





Re: Windows Presentation Foundation (WPF) Scrolling the contents of a Frame using an external ScrollViewer

Ben Carter - MSFT

In the case of ListView, since there is a ScrollViewer in its template, using the scroll wheel on that control will cause the event to be handled. This happens even when all items in the ListView are visible, meaning the ScrollViewer has nothing to scroll. Since the event is handled, the outer ScrollViewer will not respond to the handled message.

It also sounds like you are running into the case where you want a ScrollViewer to be present, but you don't want two. One possibility would be to have your setup of a ScrollViewer around a Frame, but begin with VerticalScrollBarVisibility="Disabled" (also repeat for horizontal). Attach to the LayoutUpdated event on the Frame. In that event handler, if the Frame's ActualHeight exceeds the bounds of some parent (you'll have to ensure that there is a parent that won't be larger than the window), then set the ScrollViewer's VerticalScrollBarVisibility to Visible. You'll have to be careful about causing an infinite loop in case the state decides to flip-flop, but in general I believe this should work.

Ben






Re: Windows Presentation Foundation (WPF) Scrolling the contents of a Frame using an external ScrollViewer

Nigel Page

Thanks Ben. The frame lives inside a Grid cell, so I should be able to use that as the parent and follow your suggestion. I'll try this as soon as I get back from leave, but I believe you've nailed the problem:-)