SetFocusOnEntryCompletedBehavior
이 값은 Behavior
SetFocusOnEntryCompletedBehavior
완료될 때 지정된 VisualElement
항목에 포커스를 Entry
제공하는 값입니다. 예를 들어 페이지에는 순서가 여러 Entry
가지 있을 수 있으며, 이렇게 하면 자동으로 전환된 포커스를 다음Entry
으로 완료 Entry
하는 경우 사용자에게 편리합니다.
구문
다음 예제에서는 소프트 키보드의 SetFocusOnEntryCompletedBehavior
Entry
단추를 누를 때 Next
다른 Entry
단추에 포커스가 지정되도록 추가 하는 방법을 보여 줍니다.
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>
SetFocusOnEntryCompletedBehavior 사용
XAML SetFocusOnEntryCompletedBehavior
에서 다음과 같이 사용할 수 있습니다.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="CommunityToolkit.Maui.Sample.Pages.Behaviors.SetFocusOnEntryCompletedBehaviorPage"
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">
<VerticalStackLayout Spacing="12">
<Entry
x:Name="FirstNameEntry"
toolkit:SetFocusOnEntryCompletedBehavior.NextElement="{x:Reference LastNameEntry}"
Placeholder="Entry 1 (Tap `Next` on the keyboard when finished)"
ReturnType="Next" />
<Entry
x:Name="LastNameEntry" />
</VerticalStackLayout>
</ContentPage>
C#
SetFocusOnEntryCompletedBehavior
C#에서 다음과 같이 사용할 수 있습니다.
class SetFocusOnEntryCompletedBehaviorPage : ContentPage
{
public SetFocusOnEntryCompletedBehaviorPage()
{
var firstName = new Entry
{
Placeholder = "Entry 1 (Tap `Next` on the keyboard when finished)",
ReturnType = ReturnType.Next
};
var lastName = new Entry();
SetFocusOnEntryCompletedBehavior.SetNextElement(firstName, lastName);
Content = new VerticalStackLayout
{
Spacing = 12,
Children =
{
firstName,
lastName
}
};
}
}
C# 태그
패키지 CommunityToolkit.Maui.Markup
는 C#에서 이 동작을 사용하는 훨씬 더 간결한 방법을 제공합니다.
using CommunityToolkit.Maui.Markup;
class SetFocusOnEntryCompletedBehaviorPage : ContentPage
{
public SetFocusOnEntryCompletedBehaviorPage()
{
Content = new VerticalStackLayout
{
Spacing = 12,
Children =
{
new Entry { ReturnType = ReturnType.Next }
.Assign(out var firstName)
.Placeholder("Entry 1 (Tap `Next` on the keyboard when finished)"),
new Entry()
.Assign(out var lastName)
}
};
SetFocusOnEntryCompletedBehavior.SetNextElement(firstName, lastName);
}
}
예제
.NET MAUI 커뮤니티 도구 키트 샘플 애플리케이션에서 이 동작의 예를 찾을 수 있습니다.
API
.NET MAUI 커뮤니티 도구 키트 GitHub 리포지토리에서 오버에 대한 SetFocusOnEntryCompletedBehavior
소스 코드를 찾을 수 있습니다.
.NET MAUI Community Toolkit