This port allows for Uno-based apps to use behaviors on Windows, iOS, Android and WebAssembly.
The WinUI Uno.Microsoft.Xaml.Behaviors.WinUI.Managed and UWP Uno.Microsoft.Xaml.Behaviors.Uwp.Managed Nuget packages is available.
To install the WinUI behaviors in .NET class libraries, such as the ones found in Uno Platform 4.7, use the following:
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows10.0.19041.0'">
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-windows10.0.19041.0'">
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.3.0" />
</ItemGroup>
You may need to adjust net6.0-windows10.0.19041.0
to the TargetFramework value found in your project.
XAML Behaviors is an easy-to-use means of adding common and reusable interactivity to your Windows UWP applications with minimal code. It is available for both native and managed applications. Use of XAML Behaviors is governed by the MIT License
Where to get it
- NuGet package for Native and Managed
- Source Code
Resources
More Info
For an example of using Behaviors in an application, here is a snippet of XAML:
<Button>
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Click">
<Core:ChangePropertyAction PropertyName="Background">
<Core:ChangePropertyAction.Value>
<SolidColorBrush Color="Red"/>
</Core:ChangePropertyAction.Value>
</Core:ChangePropertyAction>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Button>
The documentation explains how to install Visual Studio, add the XAML Behaviors NuGet package to your project, and get started using the API.
What You Need
Clone the Repository
- Go to 'View' -> 'Team Explorer' -> 'Local Git Repositories' -> 'Clone'
- Add the XAML Behaviors repository URL (https://github.com/Microsoft/XamlBehaviors) and hit 'Clone'
Build and Create Managed XAML Behaviors NuGet
- Open the "BehaviorsSDKManaged.sln" solution in Visual Studio
- Change Build Configuration to Release
- Build [Ctrl + B]
- Run msbuild /t:Pack src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions.Design/Microsoft.Xaml.Interactions.Design.csproj
- (Optional) Add /p:TimestampPackage=true to include the timestamp in the NuGet package version
Build and Create Native XAML Behaviors NuGet
- Open the "BehaviorsSDKNative.sln" solution in Visual Studio
- Batch Build for x86, x64, and ARM in Release
- Run msbuild /t:Pack src/BehaviorsSDKNative/Microsoft.Xaml.Interactions.Design/Microsoft.Xaml.Interactions.Design.csproj
- (Optional) Add /p:TimestampPackage=true to include the timestamp in the NuGet package version