Behaviors make it easier for designers to be able to do cool things that would otherwise require writing code. Of course, a behavior doesn’t just magically appear out of thin air.* It requires someone actually writing it.
While one our goals was to make it easy for someone to write a Behavior, there is a certain amount of boilerplate code that you need to be aware of before you get to writing code that is more familiar to you. To help make that process easier, we are going to be providing Item Templates that can be accessed from both Expression Blend 3 as well as Visual Studio 2008.
Here are the Action, Behavior, and Trigger item templates in Blend 3:
…and here they are in Visual Studio:
These item templates contain the boilerplate code I referred to earlier, so with a few clicks, you are up and running with something that Blend recognizes as a Behavior, Action, or Trigger
For example, here is what a Trigger looks like when created via our Item Template:
- public class Trigger1 : TriggerBase<DependencyObject>
- protected override void OnAttached()
- // Insert code that you want to run when the Trigger is attached to an object.
- protected override void OnDetaching()
- // Insert code that you would want run when the Trigger is removed from an object.
- // To invoke any associated Actions when this Trigger gets called, use
- // this.InvokeActions(o) where o is an object that you can pass in as a parameter
We create all of the infrastructure code that makes your Trigger a trigger, and we also provide you with some helpful comments on what to do. Because our behaviors functionality requires referencing a DLL that we provide, that referencing step is taken care of automatically for you as well. Wouldn’t it be great if everything in life were as simple as this? Ok, I’ll stop now!
How this is Possible
Everything I’ve written above uses the Item Templates format documented on MSDN. What is new is how these templates get installed. We will be releasing in the near future a standalone Expression Blend SDK that makes it possible for you to create and redistribute the various new components we introduced as a part of Blend 3. You can read more about this on a blog post I wrote for the Expression Blend & Design team blog.
*That feature is currently being prototyped in an underground bunker in an undisclosed location.