开发者

IQ test to screen coordinates in Silverlight

I have an IQ test result which ranges from 40 to 180 and that scale shows up on screen 50 pixels from the bottom and 50 pixels from the top.

In silverlight I position the first keyframe of the textbox i want to move 50 pixels from the bottom and programmatically set the end keyframe to where i want it animated to programmatically.

I am pretty much stumped with the scaling formula as to how to where to tell the object to move on the screen.

I would also like to reverse the formula to place the IQ value inside the textbox using the y position as I want value to follow the position based on easing.

        marginBottom =开发者_开发技巧 ResultText.Margin.Bottom; // the start position of the textBlock
        marginTop = EndPosition.To.Value; // the position i want it animating to

        EndPosition.To = ((iq/(180-40))*(marginTop-marginBottom)); // where to move it relating to iq

        AnimateUp.Begin(); // This is the storyboard

and then in the CompositionTarget_Rendering handler I'm looking to reverse the formula to show the iq value in the textblock that is animating.


Assuming IQ 40 should be at marginBottom and IQ 180 should be at marginTop

the formula would be

EndPosition.To = ( (marginTop - marginBottom)*iq + 180*marginBottom - 40*marginTop )/140;

Not having the full code its hard to tell, but you might have a bug in that you're determining marginTop from "EndPosition.To.Value", but you change "EndPosition.To" for the animation.

If you don't set "EndPosition.To" back to its original value, marginTop will never be the same thing twice. Just something to watch out for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜