WPF : Blend 3 Interactions / Behaviours

As part of the new Blend3 release, there is a new Dll called &#34;Microsoft.Expression.Interactivity.dll&#34;. This Dll is a pretty cool thing, as it formalises a pattern that many WPF developers have probably already used, in their own manner. It basically formalises the &#34;Attached Behaviour&#3

As part of the new Blend3 release, there is a new Dll called "Microsoft.Expression.Interactivity.dll". This Dll is a pretty cool thing, as it formalises a pattern that many WPF developers have probably already used, in their own manner. It basically formalises the "Attached Behaviour" pattern, which was possible prior to this Dll being available by the use of Attached DPs.

Can you see that we are able to add behaviours by the use of a new property "Behaviours". So that’s all cool so what does one of these here behaviours actually look like. Well there are a couple over at the Expression Blend gallery (http://gallery.expression.microsoft.com/site/items/behaviors), but for now lets have a look at one that I conjured up using. This one is a Resize Behaviour that when attached to an element will allow it to be resized using a ResizeAdorner which is hosted in the AdornerLayer.

TargetedTriggerAction(s)

Another nice thing in the "Microsoft.Expression.Interactivity.dll", is TargetedTriggerAction<T>, these are really cool, and allow an aribtary action to be performed against an Event. For example using these TargetedTriggerAction<T>, we are easily able to run a Command when a UIElement.MouseRightButtonUp occurs. Which previously was quite a task and actually almost would require some dynamically emitted assembly or IL.

Lets check these out next. Firstly in the XAML we can do something like

Which as you can see will fire the CommandAction when the MouseRightButtonUp RoutedEvent occurs for the Border in which the EventTrigger is declared. If we now focus our attention to the CommandAction implementation (again this is from the Expression Blend gallery http://gallery.expression.microsoft.com/site/items/behaviors) :