Skip to content
Fons Sonnemans edited this page Dec 6, 2018 · 8 revisions

Introduction

XAML Behaviors for WPF is an easy-to-use means of adding common and reusable interactivity to your WPF applications with minimal code. Use of XAML Behaviors for WPF is governed by the MIT License

Getting Started

Where to get it

Resources

More Info

Code Example

For an example of using Behaviors in an application, here is a snippet of XAML:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
        Title="MainWindow"
        Height="450"
        Width="800">
    <Grid>
        <behaviors:Interaction.Behaviors>
            <behaviors:FluidMoveBehavior AppliesTo="Children" />
        </behaviors:Interaction.Behaviors>

        <Rectangle Fill="Blue"
                   Width="100"
                   Height="100">
            <behaviors:Interaction.Triggers>
                <behaviors:EventTrigger EventName="MouseLeftButtonDown">
                    <behaviors:ChangePropertyAction PropertyName="Fill">
                        <behaviors:ChangePropertyAction.Value>
                            <SolidColorBrush Color="Red" />
                        </behaviors:ChangePropertyAction.Value>
                    </behaviors:ChangePropertyAction>
                </behaviors:EventTrigger>
            </behaviors:Interaction.Triggers>
        </Rectangle>
    </Grid>
</Window>

Using Behaviors SDK

The documentation explains how to install Visual Studio, add the XAML Behaviors NuGet package to your project, and get started using the API.

Building Behaviors from Source

What You Need

Clone the Repository

Build and Create Managed XAML Behaviors NuGet

  • Open a Visual Studio developer command prompt
  • Navigate to the Xaml Behaviors for Wpf repository
  • Run msbuild src\Microsoft.Xaml.Behaviors\Microsoft.Xaml.Behaviors.csproj /t:Pack

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.