Current value of an animating property of a UWP Composition visual? - c#

I have a SpriteVisual for which I'm animating opacity, offset, and size using KeyFrameAnimations. While the animation is running the property values seem to be unaffected: they show the initial values until the animation finishes, at which point they update to the final values.
I would like to be able to get the current value part-way through the animation without having to either stop the animation to synchronise the properties or to store a separate copy of the animation and the time it started in order to calculate the value myself.
Is this possible?

As far as I known, it is impossible.
When we use the StartAnimation method of the SpriteVisual class to add the KeyFrameAnimation to it and start the animation, that there is no method to get the current value.
We can use the KeyFrameAnimation and the SpriteVisual to change the value of the property during the animation.There is an ForegroundFocusEffects sample that you can refer it, it uses the ScalarKeyFrameAnimation and set the Duration of the animation.

Related

How to refresh animation state in unity to know what animation is playing

Ok so, I did this:
print(Anim.GetCurrentAnimatorStateInfo(0).shortNameHash);
When I play an animation like so
Anim.Play("AnimationName");
The value printed changes and then stays the same and doesn't change back to the default animation.
I also tried with the following:
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("FireAnimation"))
I want to be able to get a constant update on the current animation that is playing. If you have any method that doesn't involve using a clock please do help.
I realized the best way to do this is to use the animation controller and change varialbes using SetBool(); and SetFloat(); etc.

How to stop storyboard but keep current values in UWP code-behind?

What is my actual problem?
I want to stop Storyboard animation but keep current value of animated properties and unfreeze those properties.
What I have tried?
I tried storyboard.Pause() but this will keep the animated properties frozen. (changing values has no effect) I want to be able to release all properties from storyboard.
storyboard.Stop() doesn't work because it either sets value of animated properties to end or start of the animation depending on the FillBehavior. Although it will unfreeze the properties.
I tried clearing storyboard.Childern but it throws exception unless storyboard is fully stopped.
I tried to make new storyboard with duration 0 with same animations, this will stop previous animations and storyboard it self will finish in no time, but here are the problems
I should know what animations were added in last storyboard (I already solved this by storing dependency objects with property path in a List)
I have to retrieve current value of animated properties from property path.
I am stuck at the last one because this does not exist in UWP
string propertyPath = "(UIElement.Projection).(PlaneProjection.RotationY)";
// all animated properties are double
double value = (double)dependencyObject.GetValue(???);
GetValue requires DependencyProperty but i have a string.
Note: I just want a solution to my actual problem (top of this post).
I was able to solve this problem using following timeline
new DoubleAnimation { By = 0, Duration = TimeSpan.Zero }
With this timeline i don't have to know value of the properties. new storyboard on same elements and same property path's with duration 0 with this timeline will stop previous storyboard and keep their values. the new storyboard will also stop in no time and unfreeze the animated properties.

Correct/Incorrect usage of delegates for achieving extensibility

I'm trying to give users of my GUI library unrestricted customization of in/out transition effects while still maintaining simplicity / preventing misuse (for when a Control enters or exits the view).
To do so, I added a delegate to the Control class, which would take a Control reference and a transition-completion percent, so that the user would be able to smoothly translate a control's position / opacity in any way he wanted, based on the given percent. All he'd have to do is subscribe a transition function before control entrance/exit.
However, I realized it would be impossible to transition / animate the controls using only the current completion percent, because you'd have to store and compare the control's initial position as well.
In order make this storage requirement apparent, should I force usage of a delegate-functor?
If so, how might I do that in a minimalistic / clean way?
Feel free to suggest another way to allow users to apply custom transition animations!
If I understood you correctly, your Control invokes Animation(calculation) delegate (from time to time, probably on each frame) and passes transition Competition percent.
The Animation delegate then calculates and returns/applies translation and position to the Control.
Is this correct?
Assuming that above is correct there are several solutions:
When animating only position and opacity:
Beside competition percent, you must also send initial state of control's position and opacity when calling delegate. Initial state must be remembered on the transition start and sent into delegate in each call.
When animating arbitrarily properties in general:
Beside competition percent, you also provide State property (type of Object or even better Dictionary). This State property is fully controlled by delegate and it's animation logic.
To your Control, State property would not have any semantics or meaning.
Your Control only MUST retain value of State property between subsequent calls to delegate.
Putting it all together, The Delegate fills the State with the initial values on the first call, uses these values on subsequent calls - does anything it wants. Delegate also applies calculated values to Control. Note that all properties that can be used in delegate must be public.
IMO you don't have to provide the user of the control with the initial position of the control since he can position it relatively to the initial position:
negative numbers are for left and top, and positive numbers are for right and bottom.
The following code is a function for a fast transition:
Point FastTranDiagonial(float Percentage){
Thread.Sleep(10);
int pixelsDist = (1 - Percentage)* 300;//300 is the maximum distance
return new Point(-pixelsDist ,pixelsDist);
}
When you invoke the delegate you have to add the Point to the initial position of the control. You have to notice that the delegate contains a Thread.Sleep(X), this must be in control of the user since he might want to do a fast or a slow transaction.
You might also want to consider adding sequential transitions like jQuery so one transition starts after an other's completion.
good luck
I think you need to pass in at least the following parameters to the delegate:-
the control itself
the container that contains the control (eg. a panel)
the completion percent
By passing the control itself, the user will have all its initial state information (such as position). Also, if the user need to set any property of the control, he will definitely need the reference to the control itself.
The container may be needed by the user if he needs its size/position information, or if he needs to do something special to it for the control.

WPF Window Top Won't Change

I am using animations with my window to slide out or slide back up.
But when these animations are not used.
I would like to use Window.Top to set the position of the window,
but I think due to animations I cannot set the top.
I was wondering if anyone knows how to fix this? Thanks
example.
window.top is already = 33.
but when is ay
window.top =900;
it will stay at 33.
Manual value changes are ignored while an animation is running. You need to remove the animation from the property entirely to make the manually-set values visible.
If you started your animation with a BeginStoryboard action, use a RemoveStoryboard action to remove it:
<RemoveStoryboard BeginStoryboardName="NameOfStoryboard" />
If you applied your animation in code or otherwise, the trick is to pass "null" into the BeginAnimation method to remove it:
window.BeginAnimation(Window.TopProperty, null);
In many cases you can call a Storyboard's Remove method to reset the value source from an animation back to the original source, in this case your explicit value. If you could post some code it would be easier to get a more definitive answer.
Try setting FillBehavior="Stop" in your animation.

How can I dynamically move/resize a form?

I am doing an alert system that will show messages 'a la' Messenger, and I want them to move or resize to make them appear.
How can I do this without having to do this:
do
{
this.prop += 1;
} while (this. prop = destination);
You need to make a Timer component and call the form's SetBounds method in the timer's Tick event.
You need a frame rate independent interpolator.
Take a look at: Frame Rate Independent interpolation. Basically, the idea is that you compute what your current position should be based upon the expected animation time and how long you've been animating... This means that the animation will take the same amount of time to go from point a to point b on any hardware.
Of course, you'll need to position the form with the values coming out of this, but thats the easy part!
set form.size property to change size, form.position to change position

Categories

Resources