Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello there. I have an animation for an image in CSS, where using @keyframe, it shows parts of an image in order, and loops doing so. eg; link to my site page

How could I do that in WPF/XAML?
Posted
Comments
[no name] 1-Jun-14 17:54pm    
I don't know about anyone else but I would probably use a ColorAnimationUsingKeyFrames based on the information that you have given us.
uplusion23 1-Jun-14 18:40pm    
How would this work? [I'm super new to WPF/XAML]
Edit: Here's a snippit of what I've got

<Image x:Name="loader" Source="loadingicon.png" >
<Image.Clip>
<rectanglegeometry rect="0,0,0,0">
</Image.Clip>
<Image.Triggers>
<eventtrigger routedevent="Image.Loaded">
<eventtrigger.actions>
<beginstoryboard>
<storyboard>
<coloranimationusingkeyframes storyboard.targetproperty="RectangleGeometry.Rect" storyboard.targetname="loader" duration="0:0:6" repeatbehavior="Forever">
<coloranimationusingkeyframes.keyframes>

<!-- Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
a smooth, linear animation between values. -->
<LinearColorKeyFrame Value="Red" KeyTime="0:0:2" />

<!-- In the next half second, go to yellow. DiscreteColorKeyFrame creates a
sudden jump between values. -->
<discretecolorkeyframe value="Yellow" keytime="0:0:2.5">

<!-- In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame
creates a variable transition between values depending on the KeySpline property. In this example,
the animation starts off slow but toward the end of the time segment, it speeds up exponentially.-->
<splinecolorkeyframe value="Green" keytime="0:0:4.5" keyspline="0.6,0.0 0.9,0.00">


<!--<Image Source="loadingicon.png" />-->




</Image.Triggers>
</Image>
Sergey Alexandrovich Kryukov 1-Jun-14 21:58pm    
CSS? In WPF? What are you even talking about?
—SA
uplusion23 1-Jun-14 21:59pm    
I'm hoping to integrate keyframes the same way in xaml as I do in CSS.
Sergey Alexandrovich Kryukov 1-Jun-14 22:05pm    
How CSS can be related to WPF?

Either use ColorAnimationUsingKeyFrames, or, if you need something more general, use direct animation using a thread and update the UI using Dispatcher.Invoke...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900