Zooming using only keyboard


#1

Hi,

I have a requirement where I want to perform zoom related operations with keyboard alone.
Consider, I hold Ctrl key and + would make it zoom in and - will zoom out. Also something like a reset zoom to 100 % button which will reset the zoom to 100%.

Can I do it in goXam ?


#2

As far as I can tell from your description, that is the default behavior for a GoXam Diagram. Try it in the samples.

You can see the three RoutedUICommands on the Commands class:

http://www.goxam.com/2.2/helpWPF/webframe.html#Northwoods.GoWPF~Northwoods.GoXam.Commands~DecreaseZoom.html
http://www.goxam.com/2.2/helpWPF/webframe.html#Northwoods.GoWPF~Northwoods.GoXam.Commands~IncreaseZoom.html
http://www.goxam.com/2.2/helpWPF/webframe.html#Northwoods.GoWPF~Northwoods.GoXam.Commands~Zoom.html

which call the corresponding methods of the CommandHandler.

Furthermore, CommandHandler.AddStandardBindings does setup such as:

  diagram.CommandBindings.Add(new CommandBinding(Commands.DecreaseZoom, (s,e) => DecreaseZoom(e.Parameter), (s,e) => e.CanExecute=CanDecreaseZoom(e.Parameter)));  // AllowZoom
  diagram.InputBindings.Add(new InputBinding(Commands.DecreaseZoom, new KeyGesture(Key.OemMinus, ModifierKeys.Control)));

Perhaps you have disabled zooming on your Diagram? Can the user zoom in and out using control-mouse-wheel?


#3

No. I haven’t disabled ctrl+scroll zoom in the diagram.It is working as expected. Just that I want to have a zoom feature from keyboard alone. User should be able to zoom in and out using keyboard shortcuts. I want to add the feature just for the usability.


#4

Don’t those three keyboard commands work for you in most of the samples in GoWpfDemo?


#6

Yeah that worked !!

Thanks !!


#7

Just found a issue. I could replicate it in demo app also.

I Drag and drop a node. I move it to a corner and do zoom in and then click on reset(Reset basically calls Zoom() with param value as 1 ) the node moves to random location. Just guessing may be viewports of diagram panel changes. Just attached a gif for better understanding. Node staying in the same location would be better.
com-video-to-gif%20(9)


#8

The node’s Node.location is not changing as the user scrolls or zooms. The node has not “moved” and the DiagramPanel.DiagramBounds has also not changed.

I think what’s happening is that in general the viewport (as defined by the diagram.panel.ViewportBounds) has to change due to the change in DiagramPanel.Scale. Usually, there is a minimal movement in the DiagramPanel.Position.

But when zooming using keyboard commands, it tries to maintain the middle of the viewport at the same point in model coordinates. Try the same experiment with the node at other corners of the viewport.

Also, notice what happens when you zoom in or out using control-mouse-wheel. In that case the mouse pointer tells the commands to keep the mouse point (in model coordinates) constant at that view point (in view coordinates).