Share via


UserStoppedTypingBehavior

사용자가 UserStoppedTypingBehaviorBehavior 컨트롤에 대한 데이터 입력을 중지한 경우(예EditorEntrySearchBar: ) 작업을 트리거하는 것입니다. 사용의 예로는 사용자가 검색 쿼리 입력을 중지한 경우 검색 트리거가 포함됩니다.

Important

동작을 공유하고 스타일을 통해 여러 컨트롤에 적용할 수 있으므로 .NET MAUI 커뮤니티 도구 키트 동작은 동작을 설정 BindingContext 하지 않습니다. 자세한 내용은 .NET MAUI 동작을 참조 하세요.

구문

XAML

XAML 네임스페이스 포함

XAML에서 도구 키트를 사용하려면 페이지 또는 보기에 다음 xmlns 을 추가해야 합니다.

xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

따라서 다음을 수행합니다.

<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>

다음과 같이 포함 xmlns 하도록 수정됩니다.

<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>

UserStoppedTypingBehavior 사용

XAML UserStoppedTypingBehavior 에서 다음과 같이 사용할 수 있습니다.

<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...">
                <Entry.Behaviors>
                    <toolkit:UserStoppedTypingBehavior 
                        Command="{Binding Source={x:Reference Page}, Path=BindingContext.SearchCommand}"
                        StoppedTypingTimeThreshold="1000"
                        MinimumLengthThreshold="3"
                        ShouldDismissKeyboardAutomatically="True" />
                </Entry.Behaviors>
            </Entry>
</ContentPage>

C#

UserStoppedTypingBehavior C#에서 다음과 같이 사용할 수 있습니다.

class UserStoppedTypingBehaviorPage : ContentPage
{
    public UserStoppedTypingBehaviorPage()
    {
        var behavior = new UserStoppedTypingBehavior()
        {
            StoppedTypingTimeThreshold = 1000,
            MinimumLengthThreshold = 3,
            ShouldDismissKeyboardAutomatically = true
        };

        behavior.SetBinding(UserStoppedTypingBehavior.CommandProperty, 
        nameof(ViewModel. SearchCommand);

        var entry = new Entry
        {
            Placeholder = "Start typing when you stop the behavior will trigger..."
        };

        entry.Behaviors.Add(behavior);
    }
}

C# 태그

CommunityToolkit.Maui.Markup 패키지는 C#에서 이를 Behavior 사용하는 훨씬 더 간결한 방법을 제공합니다.

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, 
            static (ViewModel vm) => vm.SearchCommand,
            mode: BindingMode.OneTime));
    }
}

속성

속성 Type 설명
명령 Icommand 사용자가 입력 제공을 중지했을 때 실행할 명령입니다.
MinimumLengthThreshold int 명령을 실행하기 전에 필요한 입력 값의 최소 길이입니다.
ShouldDismissKeyboardAutomatically bool 키보드를 자동으로 해제할지 여부를 나타냅니다.
StoppedTypingTimeThreshold int 명령이 실행될 비활성 시간(밀리초)입니다.

예제

.NET MAUI 커뮤니티 도구 키트 샘플 애플리케이션에서 이 동작의 예를 찾을 수 있습니다.

API

.NET MAUI 커뮤니티 도구 키트 GitHub 리포지토리에서 오버에 대한 UserStoppedTypingBehavior 소스 코드를 찾을 수 있습니다.