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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
10 additions and
7 deletions
-
src/Avalonia.Controls/Converters/StringFormatConverter.cs
|
|
@ -2,7 +2,6 @@ |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Globalization; |
|
|
using System.Globalization; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using Avalonia.Data; |
|
|
|
|
|
using Avalonia.Data.Converters; |
|
|
using Avalonia.Data.Converters; |
|
|
|
|
|
|
|
|
namespace Avalonia.Controls.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) |
|
|
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()); |
|
|
try |
|
|
} |
|
|
{ |
|
|
catch (Exception e) |
|
|
return string.Format(format, values.Skip(1).ToArray()); |
|
|
{ |
|
|
} |
|
|
return new BindingNotification(e, BindingErrorType.Error); |
|
|
catch |
|
|
|
|
|
{ |
|
|
|
|
|
return AvaloniaProperty.UnsetValue; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return AvaloniaProperty.UnsetValue; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|