About a month or so back, Daniel sent me an email about an idea he was working on - a fluent interface that allows developers to build professional UI complete with visual effects and how that related to my Silverlight.FX effects framework.
This morning he posted his work on creating composite animations in code that builds on top of Silverlight.FX. Very cool and super interesting! Here are a couple of examples from his post:
// Play a yellow highlight for one second when an image is clicked
Animator.WithNew(highlightImage)
.Highlight(Colors.Yellow)
.For(1.Seconds())
.When(EffectBehaviors.Clicked).Play();
// A composite animation involving multiple effects
Animator.WithNew(compositeImage)
.WithEasing(EffectEasing.QuadraticInOut)
.Move(50).For(1.Seconds())
.And().Resize(0.5, 0.5).For(1.Seconds())
.And().Spin(360).For(1.Seconds())
.And().FadeTo(0.5).For(1.Seconds())
.Play();
Check out Daniel's post for more details and to download the samples and code.
I'll be posting Silverlight.FX sources itself on github rather than a zip attachment on blog posts in the near future so folks can more easily fork and experiment with ideas and additions. The SilverlightFX repository with latest binaries is already up - feel free to start watching it to be notified of checkins I will be making.
A Fluent API
For those familiar with jQuery, this will immediately ring a bell. The fluent API pattern can really help readability of code when the semantics of the code have a natural sequence and share some shared context - as in this case, the effective animation to apply and play.
What do folks think of it? I certainly wish there were some things in the .net framework that offered this style of fluent API, as it would help make code much more manageable (CodeDOM?).
Animations and the View Model Pattern?
Daniel's work brings a thought in my mind that I'll go ahead and share. Generally a view model shouldn't be concerned about visual presentation. And animations pretty much fall into the domain of presentation. For example, the code above would be written in the code-behind associated with some UI and be a part of the presentation.
However, the sequences defined above almost seem to define a meta-animation or animation model for the actual animation that is to be played. In fact Daniel talks about animators being reusable. I wonder if there is some merit in looking at these animators as a piece of model data that can be constructed by a view model, and handed to a view via an event. In turn, the the view, which subscribes to the view model, could in response materialize an actual animation instance by applying it to a visual element. Now why would I want to do such a thing, even if I could - an animation might be the result of some user interaction that is translated into an action on the view model. The alternative would be for the view model to surface a number of properties that the view or a value converter translates those properties into an animation sequence. Any thoughts on this subject?
I've increasingly adopted the view model pattern in favor of code-behind-less views since working on Silverlight and Silverlight.FX. Maybe that explains this thought process... :-)
Posted on Friday, 12/19/2008 @ 1:03 PM
| #
Silverlight