Share via


TextCaseConverter

사용자가 TextCaseConverter 들어오는 string 형식 바인딩의 대/소문자를 변환할 수 있는 단방향 변환기입니다. 이 Type 속성은 문자열에 적용할 대/소문자 종류를 정의하는 데 사용됩니다.

메서드는 Convert 제공된 변환된 value 값을 정의된 TextCaseType으로 반환합니다. 다음과 TextCaseType 같은 방법으로 제공할 수 있습니다.

  1. ConverterParameter 변환기 바인딩에서와 같이
  2. 변환기에서 Type 속성으로 지정합니다.

ConverterParameter 옵션은 속성보다 우선합니다 Type .

ConvertBack 메서드는 지원되지 않습니다.

BaseConverter 속성

다음 속성은 기본 클래스 public abstract class BaseConverter에서 구현됩니다.

속성 설명
DefaultConvertReturnValue 을 throw할 때 IValueConverter.Convert(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception. 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters가 로 설정된 true경우에 사용됩니다.
DefaultConvertBackReturnValue 을 throw할 때 IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception. 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters가 로 설정된 true경우에 사용됩니다.

ICommunityToolkitValueConverter 속성

다음 속성은 다음에서 구현됩니다.public interface ICommunityToolkitValueConverter

속성 Type 설명
DefaultConvertReturnValue object? 을 throw할 때 IValueConverter.Convert(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception. 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters가 로 설정된 true경우에 사용됩니다.
DefaultConvertBackReturnValue object? 을 throw할 때 IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?) 반환할 기본값입니다 Exception. 이 값은 CommunityToolkit.Maui.Options.ShouldSuppressExceptionsInConverters가 로 설정된 true경우에 사용됩니다.

구문

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>

TextCaseConverter 사용

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

<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="CommunityToolkit.Maui.Sample.Pages.Converters.TextCaseConverterPage">

    <ContentPage.Resources>
        <ResourceDictionary>
            <toolkit:TextCaseConverter x:Key="TextCaseConverter" Type="Upper" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <Label Text="{Binding MyValue, Converter={StaticResource TextCaseConverter}}" />

</ContentPage>

C#

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


class TextCaseConverterPage : ContentPage
{
    public TextCaseConverterPage()
    {
        var label = new Label();

		label.SetBinding(
			Label.TextProperty,
			new Binding(
				nameof(ViewModels.MyValue),
				converter: new TextCaseConverter { Type = TextCaseType.Upper }));

		Content = label;
    }
}

C# 태그

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

using CommunityToolkit.Maui.Markup;

class TextCaseConverterPage : ContentPage
{
    public TextCaseConverterPage()
    {
        Content = new Label()
            .Bind(
                Label.TextProperty,
                static (ViewModel vm) => vm.MyValue,
                converter: new TextCaseConverter { Type = TextCaseType.Upper });
    }
}

속성

속성 Type Description
Type TextCaseType 값에 적용할 대/소문자 string 형식입니다.

TextCaseType

TextCaseType 열거형은 다음 멤버를 정의합니다.

  • None - 문자열에 특정 서식을 적용하지 않습니다.
  • Upper - 문자열에 대문자 서식을 적용합니다.
  • Lower - 문자열에 소문자 서식을 적용합니다.
  • FirstUpperRestLower- 첫 번째 문자에 대문자 서식을 적용한 다음 소문자 서식을 다시 기본 문자열에 적용합니다.

예제

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

API

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