Skip to main content

Microsoft Silverlight

Answered Question MultiScaleImage and changing the Source property at runtimeRSS Feed

(0)

jaybo_nomad
jaybo_nomad

Member

Member

35 points

11 Posts

MultiScaleImage and changing the Source property at runtime

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 Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: MultiScaleImage and changing the Source property at runtime

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.

private void msi_MotionFinished(object sender, RoutedEventArgs e)

{

if (resetViewport)

{

msi.ViewportOrigin =
new Point(0, 0);resetViewport = false;

}

}

Of course you set resetViewport to true before the assignment of original = 1.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

jaybo_nomad
jaybo_nomad

Member

Member

35 points

11 Posts

Re: MultiScaleImage and changing the Source property at runtime

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?

jaybo_nomad
jaybo_nomad

Member

Member

35 points

11 Posts

Answered Question

Re: MultiScaleImage and changing the Source property at runtime

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 Pinto
Wilfred ...

Participant

Participant

1308 points

258 Posts

Re: MultiScaleImage and changing the Source property at runtime

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
 

Wilfred Pinto
http://projectsilverlight.blogspot.com


Please remember to mark the replies as answers if they help answer your question.

Wilfred Pinto
Wilfred ...

Participant

Participant

1308 points

258 Posts

Re: MultiScaleImage and changing the Source property at runtime

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.

 

Wilfred Pinto
http://projectsilverlight.blogspot.com


Please remember to mark the replies as answers if they help answer your question.

RamsZone
RamsZone

Member

Member

160 points

159 Posts

Re: MultiScaleImage and changing the Source property at runtime

 Hello I am also facing the same problem.

Do you found any solution for it?

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities