Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The UserStoppedTypingBehavior
is a Behavior
that will trigger an action when a user has stopped data input on controls for example Entry
, SearchBar
and Editor
. Examples of its usage include triggering a search when a user has stopped entering their search query.
Important
The .NET MAUI Community Toolkit Behaviors do not set the BindingContext
of a behavior, because behaviors can be shared and applied to multiple controls through styles. For more information refer to .NET MAUI Behaviors
In order to use the toolkit in XAML the following xmlns
needs to be added into your page or view:
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
Therefore the following:
<ContentPage
x:Class="CommunityToolkit.Maui.Sample.Pages.MyPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
</ContentPage>
Would be modified to include the xmlns
as follows:
<ContentPage
x:Class="CommunityToolkit.Maui.Sample.Pages.MyPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
</ContentPage>
The UserStoppedTypingBehavior
can be used as follows in XAML:
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="MyLittleApp.MainPage"
x:Name="Page">
<Entry
Placeholder="Start typing when you stop the behavior will trigger..."
x:Name="UserStoppedTypingEntry">
<Entry.Behaviors>
<toolkit:UserStoppedTypingBehavior
BindingContext="{Binding Path=BindingContext, Source={x:Reference UserStoppedTypingEntry}, x:DataType=Entry}"
Command="{Binding SearchCommand}"
StoppedTypingTimeThreshold="1000"
MinimumLengthThreshold="3"
ShouldDismissKeyboardAutomatically="True" />
</Entry.Behaviors>
</Entry>
</ContentPage>
The UserStoppedTypingBehavior
can be used as follows in C#:
class UserStoppedTypingBehaviorPage : ContentPage
{
public UserStoppedTypingBehaviorPage()
{
var behavior = new UserStoppedTypingBehavior()
{
StoppedTypingTimeThreshold = 1000,
MinimumLengthThreshold = 3,
ShouldDismissKeyboardAutomatically = true
};
behavior.SetBinding(UserStoppedTypingBehavior.CommandProperty,
static (ViewModel vm) => vm.SearchCommand,
source: this.BindingContext);
var entry = new Entry
{
Placeholder = "Start typing when you stop the behavior will trigger..."
};
entry.Behaviors.Add(behavior);
}
}
Our CommunityToolkit.Maui.Markup
package provides a much more concise way to use this Behavior
in C#.
using CommunityToolkit.Maui.Markup;
class UserStoppedTypingBehaviorPage : ContentPage
{
public UserStoppedTypingBehaviorPage()
{
Content = new Entry
{
Placeholder = "Start typing when you stop the behavior will trigger..."
}
.Behaviors(new UserStoppedTypingBehavior
{
StoppedTypingTimeThreshold = 1000,
MinimumLengthThreshold = 3,
ShouldDismissKeyboardAutomatically = true
}.Bind(UserStoppedTypingBehavior.CommandProperty,
getter: static (ViewModel vm) => vm.SearchCommand,
source: this.BindingContext,
mode: BindingMode.OneTime));
}
}
Property | Type | Description |
---|---|---|
Command | ICommand | The command to execute when the user has stopped providing input. |
MinimumLengthThreshold | int | The minimum length of the input value required before the command will be executed. |
ShouldDismissKeyboardAutomatically | bool | Indicates whether or not the keyboard should be dismissed automatically. |
StoppedTypingTimeThreshold | int | The time of inactivity in milliseconds after which the command will be executed. |
You can find an example of this behavior in action in the .NET MAUI Community Toolkit Sample Application.
You can find the source code for UserStoppedTypingBehavior
over on the .NET MAUI Community Toolkit GitHub repository.
.NET MAUI Community Toolkit feedback
.NET MAUI Community Toolkit is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Create a UI in a .NET MAUI app by using XAML - Training
Learn how to design a UI for a .NET MAUI app using XAML.
Documentation
.NET MAUI MaxLengthReachedBehavior - Community Toolkits for .NET
The `MaxLengthReachedBehavior` is a behavior that allows the user to trigger an action when a user has reached the maximum length allowed on an `InputView`.
SelectAllTextBehavior - .NET MAUI Community Toolkit - Community Toolkits for .NET
The SelectAllTextBehavior is a Behavior that will select all text in an InputView (e.g. an Entry or Editor) when it becomes focused.
SetFocusOnEntryCompletedBehavior - .NET MAUI Community Toolkit - Community Toolkits for .NET
The SetFocusOnEntryCompletedBehavior is a Behavior that allows the user to validate a given text depending on specified parameters.