Thursday, March 06, 2008

I've heard a number of people wondering how to get mouse wheel working with DeepZoom images, unfortunately this doesn't work out of the box.

I've updated my mouse wheel sample from a little while back for Silverlight 2, the new version is really slick- Silverlight's DOM bridge is pretty powerful and I was able to do all of the browser hooks from managed code- no need for browser Javascript!

The updated project source can be found here and run from here.

Just the mouse wheel source is here.

The code to use to make a DeepZoom image zoom around the mouse:

Point lastMousePos = new Point();
double zoom = 1;

public Page() {
InitializeComponent();

this.MouseMove += delegate(object sender, MouseEventArgs e) {
this.lastMousePos = e.GetPosition(this.ZoomImage);
};

new MouseWheelHelper(this).Moved += delegate(object sender, MouseWheelEventArgs e) {

double zoom = this.zoom;
if (e.Delta > 0)
zoom *= 1.3;
else
zoom /= 1.3;

Point logicalPoint = this.ZoomImage.ElementToLogicalPoint(this.lastMousePos);

this.ZoomImage.ZoomAboutLogicalPoint(zoom, logicalPoint.X, logicalPoint.Y);
};
}

5 Comments:

Anonymous mike kidder said...

its hard to read you text and links on your website. Otherwise, thanks for sharing your code...

9:17 AM  
Anonymous Anonymous said...

very dark indeed

9:43 AM  
Blogger Bijoy Thangaraj said...

I get InitializeError- 2106 An error has occurred. for http://blois.us/Silverlight/Scrolling2/

11:00 PM  
Blogger Ram said...

Hi Guys,

I am designing SL application which resembles hardrock memorabillia. In which, i have added a new functioality to highlight a image when mouse enters the image object(Adding borders around the image,). This works as expected.

But i got a problem while zooming it, only the images getting resized , but the border remains same in the initial size.. I though any UI elements placed withinn a deepzoom canvass will automtically resized when zooming happens... am i right?? but this not happens in my scneario..

And i tried to re render the highlighted border everytime when mouse wheel moves (on Zoom function).. but it seems Mousewheel helper not updating the msi subimage co-ordinates .it just maintains the existing co-ordinates ..

i thought it should work fine... but seems there is some issues handling mousewheel move..

Can u confirm me is there a way to handle the sizechanged event when zoomin happens(on mouse wheel move) in deepzoom... i have tried that, but its not working...

And Updateayout in onmousemoveevnt is not updating the changed size of the msi elements...




Cheers

Ramesh vel

10:16 AM  
Anonymous affiliates said...

wow...really nice post but very dark, Please change the theme.
Thanks,

5:08 AM  

Post a Comment

<< Home