Silverlight, DeepZoom zooming animation - silverlight

When I set the ViewportWidth of a Deepzoom image in Silverlight the zoom level changes very quickly. Is there a way I can set the time this zooming animation should take?
Thanks

The only way to do that would be to set UseSprings to false and animate the value of ViewportWidth yourself. This will also force you to animate the the ViewportOrigin as well when performing panning operations if you want to maintain the "spring" animation of panning.
You would need to test the performance of this. It could well be that MultiscaleImage may optimise its own animations differently than when these properties are being animated externally.

Try using the MultiScaleImage.UseSprings = true and the ZoomAboutLogicalPoint() method.

Although you cannot set the timing directly, each "Spring" takes exactly 1.5 seconds. So, if you wanted to, you could leave springs on, and then calculate the difference between the current viewportwidth, the viewport width you want to go to, and try and massage the timing this way. That being said, it may look awkward, so you'd have to test it first.

Related

WPF 3D element rotation speed dynamic control

I have some 3D Geometry that resembles a wheel. I want to be able to rotate it but in a controllable way. I have a slider and I want to change the speed of the wheel's rotation according to the slider value without having to stop it. What is the best way to achieve that.
I know how to rotate it to a certain degree and I also know how to have some continuous Storyboard that rotates the wheel. But I don't know how to change that according to the slider's value.
After playing a lot with it, I did it. This is how:
Created a Storyboard with a "Forever" RepeatBehavior
In my code, as I receive info from USB -not from a slider anymore- I change the Storyboard's SpeedRatio accordingly (You can also bind it to a slider progress or whatever else)

Optimizing Canvas animation

In my XAML UI, I have 4 canvas panels.
At a time only one is visible and others are collapsed.
I am using transform to have horizontal sliding effect while displaying a canvas.
I have two options to do this:
option1:
When I want to goto a Canvas, I move all other 3 canvases out of screen because i dont know which one is currently active. Advantage of this is I have only 4 animations, one for each canvas.
option2:
I define new animation for going to a particular canvas from another particular canvas. In this case I do not need to move all three canvases but only one. But then I need to create12 animations, 3 for each canvas.
I think option 1 is memory efficient since only 4 animation instances are there but there is CPU performance overhead.
Option 2 is CPU efficient but causes memory overhead due to 12 animation instances.
Which option should i prefer?
Thanks,
Tushar
Just out of interest, have you considered using the VisualStateManager? By defining an 'OnScreen' and 'OffScreen' VisualState via a style, and applying that to each of the Canvases, you would only have to code it once, let the VisualStateManager call the whichever animation is appropriate by using VisualStateManager.GoToState() which means you don't need 12 animation instances, and you don't need to call 4 animations every state change. Best of both worlds?
If you need more information, I can provide some example code shortly.
it looks like you've thought through the implications of each approach rather well. Unfortunately, only you can answer the question that you've posed. If memory is of concern to your application, then you should go with option 1. But if your application is sensitive to being CPU-bound, then you should go with option 2.
I know that's largely a non-answer ... but as it always is with performance, you should do some profiling and testing of both approaches. You may find that the relative benefits or drawbacks of both approaches is negligible, in which case you should go with whatever option is more maintainable and easier for you to code (probably option 1) :-)

WPF tabswitch/ render takes too much time

I have a WPF application with many tabs..
in one tab.. i make a verycomplex vector drawing consisting of thousands of drawing visuals.. (this represents a machine and all elements need to be interactable..)
It takes 3/4 seconds for drawing this for the first time..After the first draw it should be done..
The problem is if i switch to another tab and comeback, it takes atlease 2,3 seconds to show the tabpage with drawing again.. Since there is no redraw, why should it take so much time..?
If the component is not going to change, you could call Freeze() on it to mark it as done. Without trying it out I don't know if that would help, but you could give it a shot.
Not all objects are Freezable. Check out the MSDN documentation for more info:
http://msdn.microsoft.com/en-us/library/ms750509.aspx
Another thing you could try would be rendering the vector art to a bitmap, and displaying that. Maybe it makes you feel icky to lose the vector precision, but if you know it's not going to change and it will look the same, what's the harm? (If you support printing or something that will require a hi-res version, you could always switch back for that operation.) For info on how to convert a UIElement to a bitmap, check out:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
Another possible solution: You don't really explain what kind of interaction you are doing with the elements, but if all you want to do is zoom and pan, a RenderTransform may be good enough (which is more efficient than a LayoutTransform and/or moving all the elements individually). I haven't played around with combining Freeze() and a RenderTransform, but you may be able to get the desired zooming while reducing the amount of layout WPF has to do.

WPF, any easy way to work with different screen resolutions?

Given a WPF Application running full screen, a fair amount of controls some of which will animate from off screen to center. I was wondering if there are any special ways to save on the amount of time required to optimize an application for different screen resolutions?
For example, using Blend I've setup some text, which is originally off screen to scroll into view. Now in design mode the start positions are static. If resolution changes the start positions will obviously not be correct.
So I guess to correct this, during app startup. I need to
Check resolution
Move the text box to the desired start location
Adjust the storyboard as required, so the frames all have correct co-ordinates depending on the res of the screen.
I don't mind doing all of this, but if there is an easier way please share!
Thanks
In WPF layout of controls should be made in such way, that when size of window or content changes, controls automaticaly resize/reposition themselves to reflect this change.
This is highly affected how your layout is made, especialy by using specific panels, that do layout of their child elements.
This is also made obvious by using device-independent units for sizes, margins and sometimes positions of controls. And also allows different kind of zooming and scaling of whole UI without any need to redesign the whole thing.
If you are trying to position your controls absolutely, either by using Canvas panel or margins, your are doing it totaly wrong.
In WPF, scene is measured in abstract units, not pixels, and controls are freely scaled. There should be no problems to center something, or what?

Wpf highlight image?

Is there any effect in WPF I could Make an image shiny etc.?
(I want to use it for a hovered image)
A mask or something like this would be great.
Try applying a BitmapEffect to the image, just keep in mind that they can be expensive to use.
OuterGlowBitmapEffect might help you.
It depends on what do you mean by "shiny". A simple way is to have each image opacity set to 0.5 and change it to 1 when mouse is in.

Resources