Browse Source

Merge pull request #8663 from AvaloniaUI/fix-stringFormatConverter

Fix and optimize StringFormatConverter.
pull/8686/head
Max Katz 4 years ago
committed by GitHub
parent
commit
5c7a0bc292
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/Avalonia.Controls/Converters/StringFormatConverter.cs

17
src/Avalonia.Controls/Converters/StringFormatConverter.cs

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Avalonia.Data;
using Avalonia.Data.Converters;
namespace Avalonia.Controls.Converters;
@ -15,13 +14,17 @@ public class StringFormatConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
try
if (values[0] is string format)
{
return string.Format((string)values[0]!, values.Skip(1).ToArray());
}
catch (Exception e)
{
return new BindingNotification(e, BindingErrorType.Error);
try
{
return string.Format(format, values.Skip(1).ToArray());
}
catch
{
return AvaloniaProperty.UnsetValue;
}
}
return AvaloniaProperty.UnsetValue;
}
}

Loading…
Cancel
Save