WPF : cvb.display and zoom

Hi @algoptic,

the program you attached (btw: please delete the bin and obj folders prior to uploading) makes use of the zoom adorner, a little built-in widget in the bottom right corner of the display that allows manipulating the ZoomFactor property of the Stemmer.Cvb.Wpf.Controls.Display object:
image
However, there are two aspects to zooming - the zoom factor and the zoom center. As the zoom adorner only manipulates the zoom factor, but not the zoom center it always invariably zooms right into the middle of the image.

There are two ways around this:

  1. Use Mouse Zoom & Pan
    When holding down the CTRL key you can change the zoom factor with the mouse wheel. While doing so, the zoom center will be nudged towards the pixel above which your mouse cursor is hovering while you rotate the wheel. You may also (while holding the CTRL key) pan (click & hold left mouse button on a pixel in the display and move the mouse) - this will change the zoom center but not the zoom factor (the same effect as with panning may also be achieved using the scrollbars at the right and bottom edge of the Stemmer.Cvb.Wpf.Controls.Display control).
  2. Add Logic to Modify the ZoomCenter
    ZoomCenter is a property of the Stemmer.Cvb.Wpf.Controls.Display control that you can affect programmatically. Unfortunately, as it is a structured value type property you cannot do it directly in a simply two way binding. I have therefore modified your code slightly to include two sliders that allow you to change the ZoomCenter in code-behind (code-behind is arguably not the most beautiful solution - a view model approach would have been nicer but to keep my changes simple I opted for code-behind). I took the liberty to add some layout code to your xaml Files for those changes.

One thing to point out about the ZoomCenter property is that it behaves similar to a control’s Width and Height property. When you set a control’s Width and/or Height it is not guaranteed that the control will be rendered using the values you have set - those values are only taken as an input to the underlying layout system which might choose to overrule your “recommendations” as it sees fit. For that reason, WPF controls also have the properties ActualWidth and ActualHeight - these reflect what the layout system ended up using.

With the Stemmer.Cvb.Wpf.Controls.Display.ZoomCenter the behavior is similar: You can use it to point out where you would like to have it, but the control may overrule it and use what is stored in the ActualZoomCenter property. To illustrate the difference in your code sample I have added two text blocks to the form that bind (one-way) to the ActualZoomCenter.

CVB_TEST_ZOOM_Modified.zip (10.4 KB)

Two more comments:

  • I noticed that in your application the AnyCPU configuration had the Prefer 32 Bit box ticked. This is a bit dangerous because on an x64 installation of 64 bit this will launch the program as a 32 bit process. However the x64 setup only installs a small subset of the Win32 DLLs. See also here for more information on this option.
  • I noticed that the Stemmer.Cvb.Aux and the Stemmer.Cvb.Forms assemblies had been added to the references. These are only needed when working with the Forms display - Stemmer.Cvb.Wpf does not rely on them and I have therefore removed them.
2 Likes