CommunityToolkit.Maui.Options를 사용하면 개발자가 CommunityToolkit.Maui를 사용자 지정할 수 있습니다. 도구 키트는 이러한 설정에 따라 다르게 동작할 수 있습니다.
.UseMauiCommunityToolkit()를 호출할 때 시작 시 Options가 할당되어야 합니다.
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInConverters(false);
options.SetShouldSuppressExceptionsInBehaviors(false);
options.SetShouldSuppressExceptionsInAnimations(false);
})
SetShouldSuppressExceptionsInConverters
true로 설정하면 CommunityToolkit.Maui.Converters.BaseConverter을 구현하는 변환기에서 Exception 예외가 발생할 경우 Exception가 catch되어 Debug.WriteLine()를 통해 로깅되고, 미리 정해진 기본값이 반환됩니다.
기본값은 false여야 합니다.
Example
이 옵션은 .UseMauiCommunityToolkit()를 호출할 때 활성화됩니다:
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInConverters(true);
})
기본 반환 값
true(으)로 설정하면 Converter에서 Exception이(가) 발생할 때 기본값이 반환됩니다.
다음 두 가지 기본값이 포함됩니다.
public object? ICommunityToolkitValueConverter.DefaultConvertReturnValue { get; set; }-
Default value returned when Convert(object? value, Type targetType, object? parameter, CultureInfo? culture)Exception예외를 throw합니다
-
public object ICommunityToolkitValueConverter.DefaultConvertBackReturnValue { get; set; }-
Default value returned when ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture)에서Exception예외가 발생합니다
-
다음은 다음의 기본값을 설정하는 예제입니다.BoolToObjectConverter
XAML
<ContentPage.Resources>
<SolidColorBrush x:Key="TrueColorBrush">Green</SolidColorBrush>
<SolidColorBrush x:Key="FalseColorBrush">Red</SolidColorBrush>
<toolkit:BoolToObjectConverter x:Key="BoolToColorBrushConverter"
TrueObject="{StaticResource TrueColorBrush}"
FalseObject="{StaticResource FalseColorBrush}"
DefaultConvertReturnValue="{StaticResource FalseColorBrush}"
DefaultConvertBackReturnValue="False"/>
</ContentPage.Resources>
C# (프로그래밍 언어)
var boolToColorBrushConverter = new BoolToObjectConverter
{
TrueObject = new SolidColorBrush(Colors.Green),
FalseObject = new SolidColorBrush(Colors.Red),
DefaultConvertReturnValue = new SolidColorBrush(Colors.Red),
DefaultConvertBackReturnValue = false
};
SetShouldSuppressExceptionsInAnimations
true로 설정되면, CommunityToolkit.Maui.Behaviors.AnimationBehavior를 구현하는 Animation가 Exception를 발생시키는 경우 Exception가 catch되어 Debug.WriteLine()를 통해 로깅됩니다.
기본값은 false여야 합니다.
Example
이 옵션은 .UseMauiCommunityToolkit()를 호출할 때 활성화됩니다.
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInAnimations(true);
})
SetShouldSuppressExceptionsInBehaviors
true로 설정하면 CommunityToolkit.Maui.Behaviors.BaseBehavior를 구현하는 Behavior가 Exception를 throw할 경우, Exception가 catch되어 Debug.WriteLine()를 통해 로그에 기록됩니다.
기본값은 false여야 합니다.
Example
이 옵션은 .UseMauiCommunityToolkit()를 호출할 때 활성화됩니다.
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInBehaviors(true);
})
.NET MAUI Community Toolkit