Open Sourcing XAML Behaviors for WPF

karan nandwani msft

Today, we are excited to announce that we are open sourcing XAML Behaviors for WPF.

In the past, we open sourced XAML Behaviors for UWP which has been a great success and the Behaviors NuGet package has been downloaded over 500k times. One of the top community asks has been to support WPF in the same way. XAML Behaviors for WPF now ships as a NuGet package – Microsoft.Xaml.Behaviors.Wpf . This will allow new features and bug fixes to be addressed faster. When a new Behavior or feature is added to the repo, it can be consumed and used almost immediately. Opening to contributions lets the Behaviors platform grow by empowering the community to set the pace and direction. While you can continue to use the Extension SDK, further development will only take place on GitHub and be published in the NuGet package under the new namespace Microsoft.Xaml.Behaviors.

Start using XAML Behaviors for WPF now!

You can install the latest version of WPF XAML Behaviors in both Visual Studio and Blend using the NuGet Package Manager:

From the package manager console:

PM > Install-Package Microsoft.Xaml.Behaviors.Wpf

From Blend Assets pane:

Like UWP, we have made updates to Blend for Visual Studio 2019.Instead of presenting a pre=populated list of Behaviors in the Assets Pane, Blend prompts the user with a link to install the NuGet Package. Clicking this link will download and reference the latest NuGet Package and populate the list with the latest and greatest Behaviors. Note that if this is an existing project which references the old Behaviors SDK, the list will be pre-populated with the Behaviors from the SDK. See below for steps to migrate to the NuGet package.

Migrating .NET Framework projects from Extension SDK to NuGet

The NuGet package ships with DLLs under the “Microsoft.Xaml.Behaviors” namespace.  Since the APIs for WPF are the same as the original Extension SDK, switching over is as easy as installing the NuGet package and updating the xmlns and the usings. Note that Behaviors are not yet fully supported on .NET Core.

Steps to migrate:

  1. Remove reference to “Microsoft.Expression.Interactions” and “System.Windows.Interactivity”
  2. Install the “Microsoft.Xaml.Behaviors.Wpf” NuGet package.
  3. XAML files – replace the xmlns namespaces “http://schemas.microsoft.com/expression/2010/interactivity” and “http://schemas.microsoft.com/expression/2010/interactions“with “http://schemas.microsoft.com/xaml/behaviors
  4. C# files – replace the usings in c# files “Microsoft.Xaml.Interactivity” and “Microsoft.Xaml.Interactions” with “Microsoft.Xaml.Behaviors”

Conclusion

A big thank you to our MVP leaders for dedicating their time and effort in helping guide this project as WPF XAML Behaviors are opened to the community.

Contributions of new and useful Behaviors are welcomed and encouraged. Have feedback, suggestions, or comments? We would love to hear them – please submit an issue on the GitHub page or email us.

3 comments

Discussion is closed. Login to edit/delete existing comments.

  • mrb 0

    I followed these steps closely to convert an F# WPF app across.
    However, even though the XAML editor intellisense sees the Interaction namespace and its members, when I come to run the app I get the following:
    XamlObjectWriterException: ‘Cannot set unknown member ‘{http://schemas.microsoft.com/xaml/behaviors}Interaction.Triggers’
    Any ideas? I have the C# sample building and running correctly so why does this go wrong in F#? 
    Versions: VS2019 Pro, F# 4.6

    • Bent Rasmussen 0

      Same issue here. Have you discovered a workaround? We are also converting an F# WPF application to .NET Core.

  • Rabi Adhikari 0

    The file builds and runs but the buttons don’t behave the same way like they did using windows interactivity dlls. Am I missing something else? I am using MVVM pattern for a WPF window to output as a DLL for an Addin. If there are any examples that I can refer to would be fantastic. Thank you!

    Using VS2019, nuget package for behaviors, framework .net 4.5.2 C#, MVVM along with Relay Command.

Feedback usabilla icon