CommunityToolkit.Maui.Options

CommunityToolkit.Maui.Options, geliştiricilerin CommunityToolkit.Maui özelleştirmesine olanak tanır. Araç seti farklı davranabilir, bu ayarlara bağlıdır.

Options çağrılırken .UseMauiCommunityToolkit()başlangıçta atanmalıdır:

var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
    options.SetShouldSuppressExceptionsInConverters(false);
    options.SetShouldSuppressExceptionsInBehaviors(false);
    options.SetShouldSuppressExceptionsInAnimations(false);
})

SetShouldSuppressExceptionsInConverters

true olarak ayarlandığında, CommunityToolkit.Maui.Converters.BaseConverter uygulayan bir dönüştürücü Exception fırlatırsa, Exception yakalanır, Debug.WriteLine() aracılığıyla günlüğe kaydedilir ve önceden belirlenmiş bir varsayılan değer döndürülür.

Varsayılan değer false olarak belirlenmiştir.

Example

Bu seçenek, .UseMauiCommunityToolkit() çağırırken etkinleştirilir:

var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
    options.SetShouldSuppressExceptionsInConverters(true);
})

Varsayılan Dönüş Değerleri

true olarak ayarlandığında, Converter bir Exception oluşturduğunda varsayılan bir değer döndürülür.

İki varsayılan değer eklenir:

  • public object? ICommunityToolkitValueConverter.DefaultConvertReturnValue { get; set; }
    • Default value returned when Convert(object? value, Type targetType, object? parameter, CultureInfo? culture) bir Exception fırlatır
  • public object ICommunityToolkitValueConverter.DefaultConvertBackReturnValue { get; set; }
    • Default value returned when ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture), Exception fırlatır

Aşağıda için BoolToObjectConvertervarsayılan değerleri ayarlamaya yönelik bir örnek verilmiştir:

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# (programlama dili)

var boolToColorBrushConverter = new BoolToObjectConverter
{
    TrueObject = new SolidColorBrush(Colors.Green),
    FalseObject = new SolidColorBrush(Colors.Red),
    DefaultConvertReturnValue = new SolidColorBrush(Colors.Red),
    DefaultConvertBackReturnValue = false
};

SetShouldSuppressExceptionsInAnimations

true olarak ayarlandığında, CommunityToolkit.Maui.Behaviors.AnimationBehavior uygulayan bir Animation bir Exception fırlatırsa, Exception yakalanır ve Debug.WriteLine() aracılığıyla günlüğe kaydedilir.

Varsayılan değer false olarak belirlenmiştir.

Example

.UseMauiCommunityToolkit() çağrısı sırasında bu seçenek etkinleştirilir:

var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
    options.SetShouldSuppressExceptionsInAnimations(true);
})

SetShouldSuppressExceptionsInBehaviors

true olarak ayarlandığında, CommunityToolkit.Maui.Behaviors.BaseBehavior uygulayan bir Behavior bir Exception fırlatırsa, Exception yakalanır ve Debug.WriteLine() aracılığıyla günlüğe kaydedilir.

Varsayılan değer false olarak belirlenmiştir.

Example

Bu seçenek, .UseMauiCommunityToolkit() çağrıldığında etkindir:

var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
    options.SetShouldSuppressExceptionsInBehaviors(true);
})