XAML Behaviors have long been a frustrating part of WPF/Silverlight development. Though incredibly useful, the libraries were distributed and maintained in a strange fashion. That problem has finally been resolved with the announcement that XAML Behaviors would be open sourced and a matching NuGet package created.

XAML Behaviors are important because they offer a way to easily add functionality to UI objects in a clean and repeatable fashion. Rather than sub-classing a control or writing repetitive code-behind logic, developers can simply add a XAML snippet. Here is an example from Anoop Madhusudanan’s blog post titled Behaviors, Triggers and Actions in Silverlight And WPF Made Simple.

Behaviors such as MouseDragElementBehavior have OnAttached and OnDetaching methods. These are primarily used to add event handlers, though they can also alter properties in ways that wouldn’t be possible using normal XAML syntax.

Behaviors are normally applied on a case by case basis. However, you can apply them more broadly using styles if you pair a behavior with an attached property.

All of this convenience comes with a price; XAML behaviors were shipped as part of Blend’s System.Windows.Interactivity library. Being separately serviced from the rest of .NET, it is often hard to come by. Even after most libraries were offered on NuGet, developers were often forced to turn to unofficial packages by well-meaning developers that (hopefully) contained the real version of the library. And even today it is hard to figure out which is the officially supported version.

With the release of XAML Behaviors for UWP, all this is changing. First and foremost, XAML Behaviors are now open sourced with repository being hosted on GitHub. Official NuGet packages are offered for both Native and Managed versions of UWP.

Contribution Model

Jon Chu writes,

A committee of Microsoft Most Valuable Professionals (MVP) leaders will evaluate contributions to maintain quality and direction of the project. This project committee will approve and comment on submitted pull requests from the community. As the open source project grows and more contributors are committed to Behaviors, we plan to restructure the project to give authority to contributors who add the most value to the project. Whether it be through code, documentation, or other means of improving Behaviors, the goal is to give the community more control over Behaviors and empower users to build and add the features they most want to see.

WPF Support

On the topic of WPF support, Jon Chu wrote,