fix: 扫描时界面会因为文件名不同而抖动的问题
This commit is contained in:
@@ -100,6 +100,43 @@ public class InverseBoolConverter : IValueConverter
|
||||
}
|
||||
}
|
||||
|
||||
public class HalfDoubleConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double d && !double.IsNaN(d) && !double.IsInfinity(d))
|
||||
return d / 2.0;
|
||||
return 400.0;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public class MiddleTruncateConverter : IValueConverter
|
||||
{
|
||||
private const int KeepTail = 10;
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not string text || string.IsNullOrEmpty(text)) return value;
|
||||
|
||||
int maxLength = 60;
|
||||
if (parameter != null && int.TryParse(parameter.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsed))
|
||||
maxLength = parsed;
|
||||
|
||||
if (text.Length <= maxLength) return text;
|
||||
|
||||
int head = maxLength - KeepTail - 3;
|
||||
if (head <= 0) return text[..maxLength];
|
||||
|
||||
return string.Concat(text.AsSpan(0, head), "...", text.AsSpan(text.Length - KeepTail, KeepTail));
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public static class ValueConverters
|
||||
{
|
||||
public static readonly IValueConverter DurationFormat = new DurationFormatConverter();
|
||||
@@ -109,4 +146,6 @@ public static class ValueConverters
|
||||
public static readonly IValueConverter DurationToSliderMax = new DurationToSliderMaxConverter();
|
||||
public static readonly IValueConverter PositionFormat = new PositionFormatConverter();
|
||||
public static readonly IValueConverter InverseBool = new InverseBoolConverter();
|
||||
public static readonly IValueConverter HalfDouble = new HalfDoubleConverter();
|
||||
public static readonly IValueConverter MiddleTruncate = new MiddleTruncateConverter();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user