Your requests to grow the XAML Behaviors platform and bring them forward to support UWP app development have been heard. Today we announce the next step: XAML Behaviors natively supported for UWP and shipping as a NuGet package (for both native and managed projects). Additionally, to build a vibrant community around the platform, Behaviors are open source and on GitHub. Now, you can help influence the future direction of Behaviors.
The History of Behaviors
Originally released for WPF and Silverlight, and based on the concept of EventTriggers in WPF, designers and developers used Behaviors as an easy means for rapidly building their apps while promoting code reuse. Behaviors encapsulate reusable functionality for elements which could be easily added to XAML without the need for more imperative code.
WIth Visual Studio 2013, Behaviors were brought forward for use in Windows 8.1 Store apps (as Extension SDKs). Now, with the Universal Windows Platform, we will ship Behaviors as a NuGet package.
What are Behaviors and Actions?
Using both Behaviors and Actions, developers can create a wide variety of interactive scenarios.
Behaviors are attached to a control or element and listen for something to happen. What that “something” is can vary from an event firing (like a mouse click) or some data changing (as when a slider is moved to change a value). When the event the Behavior was listening for happens, it triggers one or more Actions.
Actions are invoked by Behaviors and execute on a selected element or control. Some examples of Actions can range from calling a method, navigating to another page, or triggering a storyboard.
Behaviors can be seen as event listeners and handlers. The following markup listens for a button to be clicked in order to play a storyboard:
<Button x:Name="button"> <Interactivity:Interaction.Behaviors> <Core:EventTriggerBehavior EventName="Click"> <Media:ControlStoryboardAction Storyboard="storyboard1"/> </Core:EventTriggerBehavior> </Interactivity:Interaction.Behaviors> </Button>
Why are we open sourcing?
From adoption in popular frameworks to demand on UserVoice, it is clear that you want Behaviors to be bigger. It’s exactly because of this excitement that we want to open source Behaviors. Releasing as a NuGet package and hosting all Behaviors code on GitHub will allow new features and fixes to be addressed more quickly. When a new Behavior or feature is added to the repo, it can be consumed and used almost immediately. Opening up to contributions lets the Behaviors platform grow by empowering the community to set the pace and direction.
Open source model
Here’s our plan to build a vibrant community around Behaviors and open up the code.:
Behaviors will be released as an updated NuGet Package every quarter, provided there are meaningful changes. By releasing a stable version every three months, new contributions will constantly be taken into the GitHub repo and will build up the catalog of Behaviors for developers to use.
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.
Integration into Blend
In moving away from the Extension SDK approach, some changes have been made to the way Behaviors are presented in Blend for Visual Studio. These changes are reflected in Update 1 RTM release. Before, Behaviors were presented as a pre-populated list in the Assets Pane. Now, the Assets Pane prompts users with a link to install the NuGet Package. Clicking this link will download and reference the latest NuGet Package and will populate the list with all the latest and greatest Behaviors.
You will also be able to get the latest version of Behaviors in both Visual Studio and Blend using the NuGet Package Manager.
To install via the NuGet Package Console, run the following command for managed projects:
PM> Install-Package Microsoft.Xaml.Behaviors.Uwp.Managed
Philosophy and direction
Behaviors will evolve as developers contribute to the project. However, not all pull requests will be accepted and merged into the repo. Here are the four philosophy and goals for Behaviors that we hope will help guide the types of contributions we receive.
Targeting common interactive scenarios
Behaviors should be a toolkit that target a wide audience of developers and empowers them to be more productive. The Behaviors taken into the project should address common and core user scenarios that many will find value in. To ensure that developers get the most out of what is published, Behaviors that address uncommon or limited scenarios may not be accepted into the core package. However, shipping these Behaviors in other NuGet packages that express a dependency on the core Behaviors NuGet package is encouraged. The project committee is actively looking into solutions for this and will guide the project accordingly.
Writing good documentation and samples
The Behaviors GitHub page, documentation, and sample apps should be good sources to teach new developers about Behaviors, and how to use them. Whether a user is new to building apps and using Behaviors, or experienced and looking to create their own custom Behaviors, the proper resources to do whatever a developer needs and wants to do should be provided.
Concentrating on the SDK and not on the tooling
Rather than concentrating on new tooling and the authoring experience behind Behaviors, building out the platform should be the goal. Behaviors are a toolkit for developers to leverage in their apps, instead of new value editors for Blend or Visual Studio.
Co-evolving C++ Behaviors evolve instep
Behaviors support both native and managed projects. While expecting more development and contributions on the C# side, there should still be adequate C++ support. If a Behavior does not utilize reflection, considerations should be made to add a C++ version to make sure no language gets left behind.
What can I do?
Start using Behaviors now. If you previously referenced the Behaviors Extension SDK, please download and install the NuGet package and reference that. The NuGet package ships with the exact same namespace and API as the original Extension SDK in most cases, so switching over is easy. While the Extension SDK will still be supported, further development will only be pursued in the NuGet version.
Additionally, with the release of the NuGet package, some partnering frameworks are simultaneously shipping updates that support the new Behaviors package: Caliburn.Micro and Cimbalino Toolkit now leverage the new Behaviors. Check them out!
The XAML Behaviors that you know and love from building 8.1 apps are now ready for UWP, open source, and shipped as a NuGet package. Contributions of new and useful Behaviors are always welcome and encouraged.
I’d like to extend a big thank you to our MVP leaders for dedicating their time and effort to this cause and helping to guide this project as Behaviors are opened to the community.
Visit the GitHub page to learn more. If you have feedback, suggestions, or comments we’d love to hear them! Tweet using #BehaviorsGoOpenSource. Share what where you’d like Behaviors to go by submitting issues on the GitHub page or email.
This blog post was written by Jon Chu, a Program Manager on Visual Studio and .NET
Updated June 28, 2018 8:47 am