Skip to main content
Home Forums Silverlight Programming Programming with .NET - General MultiScaleImage and changing the Source property at runtime
6 replies. Latest Post by RamsZone on June 13, 2008.
(0)
jaybo_nomad
Member
35 points
11 Posts
03-15-2008 3:45 AM |
I've been partly successful at selecting a different images for MultiScaleImage (DeepZoom) programmatically at runtime. I can generally switch uri's once or twice via the "Source=" property, but eventually some overflow happens internal to the control and ViewportOrigin and ViewportWidth become huge NaNs. The number of successful transitions before it fails seems to be related either to the AspectRatio or the current Viewport when the new Source is applied.
I've tried unsuccessfully to fix this by:
1. Resetting ViewportWidth, ViewportOrigin, and calling ZoomAboutLogicalPoint both before and after the Source property assignment.
2. Calling likely sounding suspects like: InvalidateMeasure(), InvalidateArrange(), and UpdateLayout().
in various random combinations, but nothing seems to work. Any ideas on how to reset the control back to the default state when changing Sources?
Yi-Lun L...
All-Star
25052 points
2,747 Posts
03-18-2008 3:05 AM |
Hello, I think you need to use a double variable to track every zoom. You can create a variable such as:
private double original = 1;
Then in every place you zoom the image, you should also modify this variable. Something like this:
original *= 1.2;
When you switch the source of MultiScaleImage (let's call it msi), you can
msi.ZoomAboutLogicalPoint(1 / original, 0.5, 0.5);
original = 1;
Then you can go on to reset ViewportOrigin. But you must wait for one motion to complete before you can do another, or you'll run into problems. So you should handle MotionFinished event, and use a boolean value to indicate if you need to reset ViewportOrigin.
{
}
Of course you set resetViewport to true before the assignment of original = 1.
03-18-2008 1:15 PM |
Thanks Yi-Lun Luo!
Your answer got me lots closer, but it's still not quite right. My MotionFinished() handler is getting called, and resets everything correctly, but it is only called about 5 seconds after switching the Source property. This delay is always present, whether or not the mouse is used to zoom in the interim. So for 5 seconds, the image coordinates are bad (and typically the image is way outside the viewport), and then they get fixed up in the MotionFinished event handler. Here's my code (with "ZoomFactor" replacing your "original" variable):
void msi_MotionFinished(object sender, RoutedEventArgs e) { if (resetViewport) { msi.ViewportOrigin = new Point(0, 0); msi.ViewportWidth = 1.0; resetViewport = false; } }private void SwitchMultiScaleImageSource (Uri NewSource){ this.msi.Source = NewSource; this.msi.ZoomAboutLogicalPoint(1 / ZoomFactor, 0.5, 0.5); ZoomFactor = 1; resetViewport = true; // this.msi.InvalidateArrange();}
private void Button_Click_Bookcase(object sender, RoutedEventArgs e){ SwitchMultiScaleImageSource (new Uri("Bookcase2/info.bin", UriKind.Relative));}
Any further suggestions?
03-25-2008 4:27 PM |
I think the ZoomAboutLogicalSource() may have messed me up. The following works fine.
private void SwitchMultiScaleImageSource (Uri NewSource){ this.lastMousePos = new Point(0, 0); this.msi.ViewportOrigin = new Point (0, 0); this.msi.ViewportWidth = 1.0; this.msi.Source = NewSource; ZoomFactor = 1;}
Wilfred ...
Participant
1308 points
258 Posts
04-03-2008 2:29 AM |
I faced the same problem. Check out my blog post http://projectsilverlight.blogspot.com/2008/03/dissecting-hard-rock-memorabilia-and_31.html
I will try this and see if it helps! Thanks
04-05-2008 1:12 AM |
I couldn't get this to work in the collection mode. The MultiScaleSubImages count doesn't get reset - it retains the previous value! Also, I wasn't able to rearrange the subimages after changing the source property.
I am assuming this is a defect.
RamsZone
160 points
159 Posts
06-13-2008 8:45 AM |
Hello I am also facing the same problem.
Do you found any solution for it?