Beginners Guide to Silverlight 4 PathListBox Control (Part–II)
In my previous article “ Beginners Guide to Silverlight 4 PathListBox Control (Part-I) ” I described about creating your very first PathList...- Article authored by Kunal Chowdhury on .
In my previous article “ Beginners Guide to Silverlight 4 PathListBox Control (Part-I) ” I described about creating your very first PathList...- Article authored by Kunal Chowdhury on .
In my previous article “Beginners Guide to Silverlight 4 PathListBox Control (Part-I)” I described about creating your very first PathListBox control in your Silverlight application followed by creating a Circular path to position the items in the circular edge. From that article, I think you are now familiar with it.
In this post, I will demonstrate you guys how to animate the items in a specific direction. This not only guide you for animation in PathListBox but also will help you understanding the StoryBoard creation (if you are very new to Silverlight). Read the whole article and at the end don’t forget to leave your comments.
Let us start by creating a Storyboard for our previous sample application. Here we will do rotating of our circular path which when rotates will also rotate the items present in the circular path. It is very easy to create a Storyboard in Expression Blend as it gives you more power to the UI, hence we will use Blend here to design our animation.
Follow the below steps to understand about storyboard animation and begin with the example:
Once you click on the “New…” option from the dropdown, it will open up a dialog box named “Create Storyboard Resource”. This has a TextBox where you can enter the name of your Storyboard. In our example we will name it as “sb_RotatingItems”. Click “OK” to continue.
The above steps will create a blank animation for you. Now, it is time to give a visual to the animation. You will notice that the created Storyboard has been already selected in the left panel and in the UI design panel it is surrounded with a RED Border. This means that, you can now modify the storyboard in the design window. If you do any change in the UI will come under the animation.
For our example, we want to rotate it in circular way. So, let’s jump into it to create the animation. Follow the simple steps mentioned below and try to understand each one of them clearly. If you have any queries, please use the below comments/feedbacks form. I will try to answer your queries as soon as possible.
Lets make it little Zoom. You will notice the following buttons in the timeline. There are more but the followings are more useful while creating/modifying a Storyboard.
Let use create a new Keyframe (the first one at ZERO position) for our Storyboard.
Now as our first Keyframe is ready, it’s time to do some animation for a specific duration. We will do it for 5 secs. You can use any number of duration in the timeline.
It’s time for us to add the animation in the Storyboard timeline. Be sure that the last keyframe is selected in the timeline panel. We will put a rotation in this frame. As our first frame is empty, it will create an animation from that keyframe to the last one to complete the rotation.
As we need a anticlockwise full rotation of the circular path and it’s contents, put “-360” as the value to the degree input box.
Now the animation that we created here will run for a single rotation and then it will stop. But, we need infinite loop of the rotation. Follow the following steps to add a repeat count to the animation:
Clicking on “Edit Repeat Count” context menu item will open the dialog named “Edit Repeat” to the screen.
Now check in the below screenshot, there is a button called “Close Storyboard” near to the Storyboard name and the “Add new Storyboard” menu. Click on it will close the Storyboard and bring the animation to normal mode from the edit mode.
You will see an Arrow placed near to the “Close Storyboard” button. Clicking this will open up one search panel where all the storyboards attached to the page will be listed there.
Our storyboard is ready for us. But what did the Blend IDE done in the XAML page? Let’s have a look into this:
You will notice that, it added a Storyboard as a Resource to the UserControl which has a DoubleAnimationUsingKeyFrames as the child. It is targetting the Rotation property of the RenderTransform of the UI control named “path”. RepeatBehavior=”Forever” represents the looping time of the animation. Here it will be infinite. If you put 5 here, it will call the animation 5 times only.
Later you will see there are two frames in the XAML. The first Keyframe we added at very first will have a value=”0” and the last frame placed after 5sec duration will have a value=”360”. From this you can clearly understand that, the animation will start from the 0th Timeline and begin with an angle of 0 degree change and end with an angle of 360 degree after 5 sec.
Lets see more on the UI control named “path”. You will see that, it has a child called CompositeTransform wrapped with RenderTransform. This ensures that, you have a smooth animation effect either Scaling of the control, Rotation of the control, Skewing of the control or TranslateTransform i.e. positioning of the control. “CompositeTransform” will have a mixed behavior of the animation defined in the Storyboard.
As you know, our XAML code is ready but if you run the application now, it won’t run the animation. We need to call the Storyboard to run. To do this, first we have to get the reference of the Storyboard from the page Resource by specifying the storyboard name as Key. Then we have to call the Begin() method which actually runs the animation. Have a look into the code. In this example, I am adding the code in the constructor. But as your need, you can place it in any portion of the code block.
Now run your application and you will see that the Circular Path starts rotating in the anticlockwise direction. Not only that, it also started rotating the items present in the edge of the circular path.
This was a small demonstration of Storyboard creation with full coverage of animating any content control in any direction of a specified path using the new PathListBox control. Hope, this post will be useful for the beginners in Silverlight to get some basic idea on Storyboard too. Bookmark and share this to all who needs to learn about it.
Also, don’t forget to leave your comments/suggestions as this helps me to serve you better by writing more articles in Silverlight with proper steps and snapshots.
Thank you for visiting our website!
We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.
We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.