첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.15MB

▶ ValidateEntryTextChangedAction.cs

namespace TestProject;

/// <summary>
/// 엔트리 텍스트 변경시 검증 액션
/// </summary>
public class ValidateEntryTextChangedAction : TriggerAction<Entry>
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Protected

    #region 호출하기 - Invoke(entry)

    /// <summary>
    /// 호출하기
    /// </summary>
    /// <param name="entry">엔트리</param>
    protected override void Invoke(Entry entry)
    {
        bool isValid = Double.TryParse(entry.Text, out double result);

        entry.TextColor = isValid ? Colors.Black : Colors.Red;
    }

    #endregion
}

 

728x90

 

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:TestProject">
    <StackLayout
        HorizontalOptions="Center"
        VerticalOptions="Center">
        <Entry x:Name="entry"
            WidthRequest="300"
            Text=""
            Placeholder="텍스트를 입력해주시기 바랍니다.">
            <Entry.Triggers>
                <EventTrigger Event="TextChanged">
                    <local:ValidateEntryTextChangedAction />
                </EventTrigger>
            </Entry.Triggers>
        </Entry>
    </StackLayout>
</ContentPage>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요