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

TestProject.zip
0.15MB

▶ IntegerToBooleanConverter.cs

using System.Globalization;

namespace TestProject;

/// <summary>
/// 정수↔진리 값 변환자
/// </summary>
public class IntegerToBooleanConverter : IValueConverter
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo)

    /// <summary>
    /// 변환하기
    /// </summary>
    /// <param name="sourceValue">소스 값</param>
    /// <param name="targetType">타겟 타입</param>
    /// <param name="parameter">매개 변수</param>
    /// <param name="cultureInfo">문화 정보</param>
    /// <returns>변환 값</returns>
    public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo)
    {
        return (int)sourceValue != 0;
    }

    #endregion
    #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo)

    /// <summary>
    /// 역변환하기
    /// </summary>
    /// <param name="sourceValue">소스 값</param>
    /// <param name="targetType">타겟 타입</param>
    /// <param name="parameter">매개 변수</param>
    /// <param name="cultureInfo">문화 정보</param>
    /// <returns>역변환 값</returns>
    public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo)
    {
        return (bool)sourceValue ? 1 : 0;
    }

    #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">
    <ContentPage.Resources>
        <local:IntegerToBooleanConverter x:Key="IntegerToBooleanConverterKey" />
    </ContentPage.Resources>
    <StackLayout
        HorizontalOptions="Center"
        VerticalOptions="Center">
        <Entry x:Name="entry1"
            HorizontalOptions="Center"
            Placeholder="enter search term"
            Text="" />
        <Button
            Margin="0,10,0,0"
            HorizontalOptions="Center"
            Text="Search"
            IsEnabled="{Binding Source={x:Reference entry1},
                Path=Text.Length,
                Converter={StaticResource IntegerToBooleanConverterKey}}" />
        <Entry x:Name="entry2"
            Margin="0,10,0,0"
            HorizontalOptions="Center"
            Placeholder="enter destination"
            Text="" />
        <Button
            Margin="0,10,0,0"
            HorizontalOptions="Center"
            Text="Submit"
            IsEnabled="{Binding Source={x:Reference entry2},
                Path=Text.Length,
                Converter={StaticResource IntegerToBooleanConverterKey}}" />
    </StackLayout>
</ContentPage>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요