Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
CommunityToolkit.Maui.Options permite a los desarrolladores personalizar CommunityToolkit.Maui. El kit de herramientas puede comportarse de forma diferente dependiendo de esta configuración.
Options debería asignarse al inicio al llamar a .UseMauiCommunityToolkit():
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInConverters(false);
options.SetShouldSuppressExceptionsInBehaviors(false);
options.SetShouldSuppressExceptionsInAnimations(false);
})
SetShouldSuppressExceptionsInConverters
Cuando se establece en true, si un convertidor que implementa CommunityToolkit.Maui.Converters.BaseConverter produce una Exception, se capturará la Exception, se registrará a través de Debug.WriteLine() y se devolverá un valor predeterminado.
El valor predeterminado es false.
Ejemplo
Esta opción está habilitada al llamar a .UseMauiCommunityToolkit():
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInConverters(true);
})
Valores devueltos predeterminados
Cuando se establece en true, se devolverá un valor predeterminado cuando Converter produzca una Exception.
Se incluyen dos valores predeterminados:
public object? ICommunityToolkitValueConverter.DefaultConvertReturnValue { get; set; }Default value returned when Convert(object? value, Type targetType, object? parameter, CultureInfo? culture)produce unaException
public object ICommunityToolkitValueConverter.DefaultConvertBackReturnValue { get; set; }Default value returned when ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture)produce unaException
Este es un ejemplo que establece los valores predeterminados para 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
Cuando se establece en true, si un Animation que implementa CommunityToolkit.Maui.Behaviors.AnimationBehavior produce una Exception, se capturará la Exception y se registrará a través de Debug.WriteLine().
El valor predeterminado es false.
Ejemplo
Esta opción está habilitada al llamar a .UseMauiCommunityToolkit():
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInAnimations(true);
})
SetShouldSuppressExceptionsInBehaviors
Cuando se establece en true, si un Behavior que implementa CommunityToolkit.Maui.Behaviors.BaseBehavior produce una Exception, se capturará la Exception y se registrará a través de Debug.WriteLine().
El valor predeterminado es false.
Ejemplo
Esta opción está habilitada al llamar a .UseMauiCommunityToolkit():
var builder = MauiApp.CreateBuilder();
builder.UseMauiCommunityToolkit(options =>
{
options.SetShouldSuppressExceptionsInBehaviors(true);
})
.NET MAUI Community Toolkit