diff --git a/components/Behaviors/OpenSolution.bat b/components/Behaviors/OpenSolution.bat new file mode 100644 index 00000000..814a56d4 --- /dev/null +++ b/components/Behaviors/OpenSolution.bat @@ -0,0 +1,3 @@ +@ECHO OFF + +powershell ..\..\tooling\ProjectHeads\GenerateSingleSampleHeads.ps1 -componentPath %CD% %* \ No newline at end of file diff --git a/components/Behaviors/samples/AutoSelectBehaviorSample.xaml b/components/Behaviors/samples/AutoSelectBehaviorSample.xaml new file mode 100644 index 00000000..f681e837 --- /dev/null +++ b/components/Behaviors/samples/AutoSelectBehaviorSample.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/components/Behaviors/samples/AutoSelectBehaviorSample.xaml.cs b/components/Behaviors/samples/AutoSelectBehaviorSample.xaml.cs new file mode 100644 index 00000000..8fad7705 --- /dev/null +++ b/components/Behaviors/samples/AutoSelectBehaviorSample.xaml.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using CommunityToolkit.WinUI.Behaviors; + +namespace BehaviorsExperiment.Samples; + +[ToolkitSample(id: nameof(AutoSelectBehaviorSample), nameof(AutoSelectBehavior), description: $"A sample for showing how to use the AutoSelectBehavior.")] +public sealed partial class AutoSelectBehaviorSample : Page +{ + public AutoSelectBehaviorSample() + { + this.InitializeComponent(); + } +} diff --git a/components/Behaviors/samples/Behaviors.Samples.csproj b/components/Behaviors/samples/Behaviors.Samples.csproj new file mode 100644 index 00000000..95f546a6 --- /dev/null +++ b/components/Behaviors/samples/Behaviors.Samples.csproj @@ -0,0 +1,8 @@ + + + Behaviors + + + + + diff --git a/components/Behaviors/samples/Behaviors.md b/components/Behaviors/samples/Behaviors.md new file mode 100644 index 00000000..917d00fe --- /dev/null +++ b/components/Behaviors/samples/Behaviors.md @@ -0,0 +1,47 @@ +--- +title: Behaviors +author: Arlodotexe +description: +keywords: Behaviors +dev_langs: + - csharp +category: Xaml +subcategory: Behaviors +discussion-id: 0 +issue-id: 0 +--- + +# Behaviors + +A behavior is a class that attaches to a XAML control and invokes an Action when triggered. + +The `Microsoft.Xaml.Behaviors.*` packages contains several useful triggers and actions, and the Windows Community Toolkit provides even more. + +See also [XamlBehaviors Wiki](https://github.com/Microsoft/XamlBehaviors/wiki) + +## KeyDownTriggerBehavior + +A behavior that listens to a key press event on the associated UIElement and triggers the set of actions. + +> [!Sample KeyDownTriggerBehaviorSample] + +## AutoSelectBehavior + +The AutoSelectBehavior automatically selects the entire content of its associated TextBox when it is loaded. + +> [!Sample AutoSelectBehaviorSample] + +## ViewportBehavior +This behavior allows you to listen an element enter or exit the ScrollViewer viewport. + +> [!Sample ViewportBehaviorSample] + +## FocusBehavior + +Of the given targets, this behavior sets the focus on the first control which accepts it. + +A control only receives focus if it is enabled and loaded into the visual tree: +> [!Sample FocusBehaviorButtonSample] + +Empty lists do not receive focus: +> [!Sample FocusBehaviorListSample] diff --git a/components/Behaviors/samples/Dependencies.props b/components/Behaviors/samples/Dependencies.props new file mode 100644 index 00000000..e622e1df --- /dev/null +++ b/components/Behaviors/samples/Dependencies.props @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/Behaviors/samples/FocusBehaviorButtonSample.xaml b/components/Behaviors/samples/FocusBehaviorButtonSample.xaml new file mode 100644 index 00000000..1e57af3e --- /dev/null +++ b/components/Behaviors/samples/FocusBehaviorButtonSample.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + +