Blend 3 introduces a powerful design pattern for interactivity: Behaviors. Behaviors allow designers to create production-quality interactivity without writing code. They work in WPF and Silverlight.
For those of you who are missing triggers in Silverlight: Behaviors give you the same power as triggers and actions plus more, in a modular and extensible fashion, not just for WPF but also for Silverlight!
In Blend 1 and 2, there is quite a bit of interactivity that can be created without code:
- You can create animations (storyboards) and trigger their playback
- You can create working interactive control skins
- You can use data binding to automatically display data or modify the state of your user interface
- You can interactively create, apply and edit data templates that completely customize the appearance and visualization of data
For many common interactions, however, in Blend 1 and 2 you still have to fall back to code. This is even more unsatisfactory once you realize how generic a lot of common interactivity code actually is – there just usually is no good place and model to encapsulate and package bits of interactivity in a reusable, designer-friendly manner.
Blend 3 therefore introduces a new concept called behaviors for both Silverlight and WPF. Behaviors are self-contained, re-usable snippets of interactivity that can be assigned interactively to art board content. These snippets inject their DNA, the interactivity they represent, into the element they are assigned to and make them interactive.
Designers can use behaviors right on the Blend art board – they can be applied to elements with drag and drop, and many have configuration options available through the property inspector. The building blocks of behaviors are very modular, which makes behaviors flexible and adaptive in their application. Best of all, behaviors allow designers to add production-quality interactivity to their designs. Behaviors are not just a prototyping tool that is impossible to use in a production scenario.
Developers (or, of course, designers that like to wear a developer hat once in a while) can create new behaviors in code. Once created, the behaviors show up in the Blend asset tool, similar to custom controls. Behaviors are extremely general and extensible and enable design teams to build their own re-usable vocabulary of interactivity.
For those readers familiar with Triggers and Actions in WPF: Behaviors are a logical extension to the existing models – they build on and extend the idea behind Triggers and Actions. And very importantly, with the Behaviors mechanism in Blend 3, all this power is available for Silverlight too, even though the Silverlight platform does not have built-in support for Triggers. We will talk more about the technical details behind behaviors in future posts.
Behaviors can be used for simple things, such as opening and closing dialogs, running animations, setting properties, validating input or navigating between screens. Behaviors can also be used to encapsulate complex code-driven animations.
Behaviors also can be used for more complex interaction that go way beyond what triggers in WPF can handle, such as making objects drag-able in a container. We even have written internal behaviors that simulate physics or that allow for on-the-fly scripting.
While we will ship Blend 3 with a set of standard behaviors, probably one of the best features of the behaviors pattern is that it is highly extensible – you can write your own, or even better, somebody else can write new behaviors for you. Behaviors are a great new element of the designer-developer workflow: For developers, they provide a well-supported design pattern that makes it possible to encapsulate interactivity well separated from actual UI instances. For a designer, behaviors are building blocks that make interactivity possible beyond the boundaries and limitations of classical custom controls.
Behaviors add a lot of flexibility all across Blend: Control skins can be made much more flexible using a behavior that can change visual states of a control in reaction to events. Prototypes can be brought to live with interaction behaviors. There are countless other examples.
Blend 3 will ship with a set of Behaviors useful in many general scenarios. We also plan to continuously provide additional behaviors out of band. And we of course hope that the community will begin creating and sharing behaviors as well – our new Expression Gallery is one location where you can publish your behaviors to the world. There are already several samples up there, written by members of the Blend team and the community…