Override Default Document Viewer Panning Behavior

Sep 14, 2010 at 5:47 AM
Edited Sep 14, 2010 at 5:48 AM

Currently if I hold down left mouse button and move the mouse on a page it will scroll the page in the viewer.

How can I override this?

Full stroy :

I want to implement zooming, by selecting the zoom tool button, then holding the left mouse button on the page, and moving the mouse, creating a rectangle for zoom, then as soon as I release the left mouse key zoom should function, but the current default Left Mouse Button down and Mouse Move stops me from doing this.


Sep 14, 2010 at 11:43 AM

The panning behavior of the DocumentViewer is hard-coded and cannot be overriden. There are currently two mouse modes:

  • Text selection: if an enabled TextSelection instance is assigned to the Document Viewer mouse clicks will result in text selects.
  • Panning: if no enabled TextSelection instance is available, mouse clicks result in the hard coded panning behavior.

I see the need for panning customization, so a workitem has been created to enable custom panning behavior.

For custom panning and zooming using a single FixedPageViewer see the SampleSinglePage sample updated in changeset 60459

Dec 8, 2011 at 2:18 AM

Is it possible to change mode dynamically ?

I did that :

<doc:TextSelection x:Key="Selection" IsEnabled="False" />
var Selection = (TextSelection)LayoutRoot.Resources["Selection"];

But I can't access Selection.IsEnabled to pass property to True.



Dec 8, 2011 at 2:21 PM

What do you mean with can't access Selection.IsEnabled? This should work just fine in code. Any errors or incorrect behavior?

- koen

Dec 8, 2011 at 2:25 PM
Edited Dec 8, 2011 at 2:25 PM

I would like to change IsEnabled dynamically, from a button click, during document reading.

Thank you.

Dec 8, 2011 at 2:30 PM
Edited Dec 8, 2011 at 2:30 PM

Enable the mouse selection in code:

var selection = (TextSelection)LayoutRoot.Resources["Selection"];
selection.IsEnabled = true;

And also make sure the selection instance is used by your DocumentViewer

<doc:DocumentViewer Selection="{StaticResource Selection}" />


- koen

Dec 8, 2011 at 2:37 PM

Ok, but the problem for me is : selection.IsEnabled does not exists with intellisense... I don't understand because i can use it from xaml.

Dec 8, 2011 at 2:38 PM

Maybe it's another TextSelection class? Make sure you cast to FirstFloor.Documents.TextSelection.

- koen

Dec 8, 2011 at 2:41 PM

Yes, that's true, i mapped System.Windows.Documents.TextSelection. Great !!!

Dec 8, 2011 at 2:48 PM

That makes sense.

- koen