At the Chicago .toolbox event last week, @thejeanious asked how she could easily animate an object between grid row and columns.
l originally answered with something like “I would use a Canvas and figure out the XY positioning…”, but after she explained she was working on a game where the grid seemed to be a natural fit, we came up with a different solution – the new FluidMoveBehavior that comes with Expression Blend 4.
I’ve been explaining the concept of Fluid UI, as a means to animate discrete properties. The first example that comes to mind is the Visibility property of an element. Its either Visible or Collapsed, there is no way to interpolate between the two values. When you change the Visibility property between different VisualStates and check the “Use Fluid UI” button, rather than instantly disappearing, Fluid UI will animate the opacity and scale transform to provide a visual transition between the discrete values.
This type of behavior works with Grid Row and Column positioning as well. If you attach the FluidMoveBehavior to a Grid and set AppliesTo to “Children”, and then at run-time change the Grid Row and Column properties of an element, the item will animate to its new position.
I’ve created a quick sample that demonstrates this behavior.
- Click a rectangle and the ball will animate to that rectangle’s position in the grid
- The cursor keys are also hooked up to move the ball
The beauty of this sample is that shows by quickly applying the FluidMoveBehavior I can animate the position of an element (with easing) writing very little code.
My main goal was to update the Getting Started series to take advantage of new version 4 features. I also took advantage of this update to greatly improve the Installation and Setup tutorial.
The content for the site is made for those with an interest in experimenting with Silverlight, who most likely do not have any .NET development experience or in some cases, even Windows.
As a first step, configuring your design and development environment for Silverlight can be a little daunting. Happily the installation process is now much simpler with the advent of the version 4 tools.
Nonetheless, as requested, I’ve put together a simple step by step walkthrough of the install process.
Working towards more Silverlight time and less “WTF?” time.
The new Setup tutorial takes full advantage of the Web Platform Installer (Web PI) which acts as a download and install tool for the needed Tools. This makes writing the tutorial and installing much easier.
Along with the step by step guide, I’ve also updated the Getting Started series to reflect the new v4 tools and features, specifically CompositionTarget.Rendering (which is like ENTER_FRAME) and CompositeTransform (which makes transforms simpler than before).
Next month, we’ll be updating the Flash to Silverlight site with a new set of tutorials focused on Media (codecs, players, markers, etc) and how it compares to Flash media.
Now for some Taco Bell…
The Artefact Animator library is based on the same concept as Tweener for Flash, which provides an easy way to do procedural animations in WPF and Silverlight.
I found some time last night to put together this little Xbox Live avatar mosaic and was very pleased with the results.
If you take a look at the prototype, you can see there’s a few things you can do:
- Drag the grid splitter, resize the window or change the padding slider to cause the tiles to reposition.
- Type a new Xbox Live Gamertag in the textbox and TAB out to cause the tiles to fade out and fade back in with a new image
- Roll over a tile and it will scale down until you roll off of it
You can download the source to see the full code but I’ll just highlight the areas where the Artefact Animator is used below.
Download the Library
The first thing you need to do is download a copy of the library from the codeplex site. Jesse has also posted documentation which will help you understand how to use the library. Once you have the library downloaded make sure to add a reference to your project.
Position the Avatar Tiles
When the application loads, AvatarTile controls are dynamically added to the main Canvas called LayoutRoot. Once the SizeChanged event of the Canvas is fired the updateTileLayout method is called. Calling the method at this point ensures the ActualWidth property of the Canvas is available and the tile layout will be repositioned if the browser window is resized or the grid splitter is moved.
Then we loop through the children of the Canvas and based on the index of the tile an easing function is added using the code below:
The element parameter defines which AvatarTile to animate.
AnimationTypes is an enum tied to different properties you can choose to animate.
The curX and curY parameters define the new value of the animated property.
The time parameter defines how long the animation should take to get to the new value.
The delay parameter defines how long before the animation should begin.
The ease parameter is a PercentHandler class instance used to define the type of easing function. The full list of Ease Functions is posted, along with how to create custom ease functions.
When determining the curX and curY values in the updateTileLayout method, padding is also taken into consideration. The slider sets the padding based on its position. After the slider is moved, the updateTileLayout method is called to reflect the change in padding.
Fade Out, New Image, Fade In
After a new value is entered into the textbox and the LostFocus event is fired, the AvatarTiles are faded out to reset the brush. This was a test of the available Events of the EaseObject.
After looping through the children and animating the Opacity of each element, a reference to the return value of the AddEase method is stored. This way we can add an event handler to the Completed event of the EaseObject instance. The event handler will then reset the image brush and animate the tiles back into view using the code below:
Mouse over action for the Tiles
And finally, taking advantage of some of the Shortcut functions built in, we’ll scale the AvatarTile based on the mouse over events. In the AvatarTile class, the first step is to use the handy NormalizeTransformGroup method which ensures the needed Transform objects are in place.
Once the library is upgraded to Silverlight 4, this step could become obsolete by leveraging the new CompositeTransform class.
In the Loaded event:
Then on Mouse Enter:
And to remove the effect on Mouse Leave:
And that’s it! Everything is hooked up and ready to run.
I really like the direction Jesse is headed with the library by making procedural animations easier to write in Silverlight and WPF. He’s mentioned the library is in its early stages and would love to see more people use it and provide feedback.
One of the things I found is that after changing the gamertag and fading out the tiles, the repositioning animations got very slow. I’m not sure if that’s colliding easing objects or what, but there’s some performance work that could be done there.
The other issue is that due to the nature of procedural animations there is no design-time experience. The best thing about Storyboards is that you can create them visually in Blend and preview them without having to run the application. It’d be interesting to see if there was some way to tackle this problem. Not sure what to suggest yet.
What do you think? Give the Artefact Animator a try and send your feedback to Jesse.
Expression Blend 4 Beta is out in the wild and available for download! As a companion whitepaper, check out the Expression Blend 4 Beta Feature Overview which provides a walkthrough of the new features. Here’s where we begin:
Expression Blend 4 Beta adds support for Silverlight 4 and Windows Presentation Foundation 4, while maintaining the ability to create and edit Silverlight 3 and WPF 3.5 with Service Pack 1(SP1) applications. Interoperability with Visual Studio 2010 has been added, maintaining the seamless workflow between the two tools.
In response to customers’ desires to do more without code, new features in SketchFlow enable more dynamic prototypes to be created and provide an enhanced player experience. Additionally, Expression Blend 4 Beta adds powerful new behaviors for all application types and makes them configurable with conditional statements.
Expression Blend 4 Beta introduces new features that support the Model-View-ViewModel (MVVM) pattern for business application development. New design-time data and resource features, along with behaviors such as CallMethodAction and InvokeCommandAction greatly increase the capability and experience for design tasks while building these applications.
Along with these three areas of focus, other additions include: new controls, such as the PathListBox, new pixel shader effects, transition effects and helpful tooling improvements.
Expression Blend 4 Beta is an exciting update that continues to revolutionize the speed and efficiency with which you can take your ideas from concept to completion on the Silverlight and .NET platforms.
The rest of the paper is divided into the following topics:
- SketchFlow Improvements for Better Prototypes
- Enabling Business Application Development with MVVM
- New Controls and Effects for Dynamic Interfaces
- More Interactivity and Less Code with New Behaviors
- Editor and Tooling Improvements
- and Expression Blend Resources
I hope you find the Expression Blend 4 Beta Feature Overview useful and that you share your feedback. We want to make sure the overview for the final release is even better!
We just shipped a major update to the Project Rosetta site, including a new a series of Flash to Silverlight tutorials, an updated API Guide with a quick reference list and a full list of recommended tools, code samples and frameworks to download.
- Setting up the Tools
- The Beginning
- Storyboard Animation
- Procedural Animation
- Color Scale and Rotation
- Quick Reference
- Fundamentals and Tools
- Graphics and Images
- Displaying Objects
- MovieClip to UserControl
- Flex Components to Controls
And this is just the beginning – you can look forward to new tutorials in the Getting Started series, along with new series of tutorials that go deeper into a single topic.
I’ve done a few events recently and two of the topics that come up when talking to attendees include additional resources for learning and tutorials that I’ve written myself that that demonstrate a technique they’re asking about.
I’ve been keeping track of my favorite resource here on this Additional Resources page, which includes learning resources and a list of Microsoft and Community people to follow via their blogs or twitter.
One thing I did not have, though, was a list of all the tutorials and labs that I’ve written.
So, I’ve put together a new Tutorials page that lists all of the recent Silverlight 3, Expression Blend 3 and Silverlight 4 Beta tutorials and labs I’ve been worked on. This will be helpful for me when trying to refer back to past content, and hopefully it will be useful for you as well in case something in there address or introduces you to a new concept.
I have a list of 34 pieces of content to start with, but my current queue of tutorials includes 11 more ideas in the works. There are plenty more ideas in my head, though, so I’m going to set a goal of 60 by the end of June.
As a big fan of graphics, UI work and Blend, I will likely be focusing there. Certainly one of the most requested topics lately is skinning controls and application themes.
What do you want to learn about?